38 users online (0 members and 38 guests)  


  Results 1 to 2 of 2

Related

  1. validating the checkbox,list/menu..    Forum: Javascript Forum
    Replies: 8
  2. Validating Integer in Javascript    Forum: PHP Forum
    Replies: 2
  3. Replies: 4
  4. CSS not validating    Forum: CSS Forum
    Replies: 2
  1. #1
    hermoine's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Mar 2007
    Posts
    32

    Lightbulb validating a form

    In my project i need to validate each and every input field in every page. i am totally getting confused with this. i tried a few sites. but its not helping me.

    Every where they are checking only one validate function for each input. eg. for the input boxes they check only isEmpty? or format of the input.

    But i want to check every input for the following :

    1. null value

    2. format

    3. if redundant with already exisitng value
    etc.

    can you help me with this. can you suggest me any site?

  2. #2
    hermoine's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Mar 2007
    Posts
    32

    Lightbulb Re: validating a form

    i used the following code
    Code:
    //validate code
            function codeValidate(elem){
     
                    if(!isEmpty(elem,"Fill")){
                            if(isNumeric(elem,"Only Numbers")){
     
                                    if(lengthRestriction(elem,4,5)){
     
                                            return true;
     
                                    }
     
                            }
                    }
            }
    Code:
     function isEmpty(elem){
                    if(elem.value.length == 0){
                            alert("Fill");
                            elem.focus(); // set the focus to this input
                            return true;
                    }
                    else{return false;}
            }
    // If the element's string matches the regular expression it is numbers and letters
            function isNumeric(elem){
                    var numericExp = /^[0-9]+$/;
                    if(elem.value.match(numericExp)){
                            return true;
                    }else{
                            alert("Format Mismatch");
                            elem.focus();
                            return false;
                    }
            }
    //length Restriction
            function lengthRestriction(elem, min, max){
                    var uInput = elem.value;
                    if(uInput.length >= min && uInput.length <= max){
                            return true;
                    }else{
                            alert("Please enter between " +min+ " and " +max+ " characters");
                            elem.focus();
                            return false;
                    }
            }
    I am giving codeValidator in the onblur event of the 1st textbox

    But if i go to the 2nd text box without filling anything in the 1st textbox then i get the alert box "Fill" . But even if i give ok it does not go. it is coming again and again.

    What is wrong with the code. i am not able to rectify this. i am struggling with this for the past two days.



Tags for this Thread