has anyone successfully done JavaScript validation


Web tier: servlets, JSP, Web frameworks: has anyone successfully done JavaScript validation

  1. Hi
    Though this is not theclientside.com...i have not been able to get a successful script that checks userinput in a textfield at runtime and only allows numbers upto 2 decimals. Has anyone been able to solve this?

  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">


    <script language = "Javascript">

    function CheckNumber(){
            var Val=document.frmSample.txtNumber;
            var i;
            var len = Val.value.length;
            var err = "The field should be a number and must be 2 in length";
            if ((Val.value==null)||(Val.value=="") || (len < 2)){
                    return false;

        for (i = 0; i < len; i++)
            // Check that current character is number.
            var c = Val.value.charAt(i);
            if (((c < "0") || (c > "9"))) {
    return false;
        // All characters are numbers.
        return true;


    <form name="frmSample" method="post" action="#" onSubmit="return CheckNumber()">
                    Enter a phone number :
                      <input type="text" name="txtNumber" maxlength="2" >
                      <input type="submit" name="Submit" value="Submit">