How to pass a value from the Jquery validation

Posted by user2963960 on Stack Overflow See other posts from Stack Overflow or by user2963960
Published on 2013-11-07T15:48:55Z Indexed on 2013/11/07 15:53 UTC
Read the original article Hit count: 226

Filed under:
|

How can i pass a value from the jquery validation. I have an input box named clubCardNumber it should validate the length of the inputted value. If the length is equal to 10 the value passes to the hidden field named else validated it if its null or empty if all validations are true then its a clubCard.

Here is how i implemented it on Javascript

 function validateClubCardNumber() {

    var varClubCardNumber = $('#clubCardNumber').val();     
    $('#phoneNumber').val("");
    var returnVal = true;

    if ((null == varClubCardNumber || '' == trim(varClubCardNumber)){
        return false;
    }
    if( varClubCardNumber.length < 10 ){
            return false;

    }else if( varClubCardNumber.length == 10 )  {
        //The Phone Number field should contains numbers only
        var pattern  = /^[0-9 -]*$/ ;
        var flag = pattern.test(trim(varClubCardNumber));
        if(flag == false){
            return false;
        }else{
            $('#phoneNumber').val(varClubCardNumber);
            returnVal = true;
        }
    }

    }
    return returnVal;
 }

HTML

<div >
   <label for="clubCardNumber" >Card or Phone Number:</label>
   <input id="clubCardNumber" name="clubCardNumber" type="text" placeholder="Card or Phone Number" value="" maxlength="20"/>
</div>
<input type="hidden" id="phoneNumber" name="phoneNumber" value=""/> 

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about validation