Help adding custom validators to the jquery.validator-0.3.4.min.js

Oct 23, 2012 at 10:45 AM

Good Day

Pls  how can i create a custom validators for mobile "((\+63)|0)[.\- ]?9[0-9]{2}[.\- ]?[0-9]{3}[.\- ]?[0-9]{4}"..,

 

Thanks

Moises Bas

Coordinator
Oct 26, 2012 at 9:56 PM

There are two ways you can do this, either use the regular expression validator:

<input type="text" validate="group" regular="Invalid mobile, please check for typos." validExpress="((\+63)|0)[.\- ]?9[0-9]{2}[.\- ]?[0-9]{3}[.\- ]?[0-9]{4}" />
<input type="submit" value="Submit" onclick="return validate('group');">

Or you can create your own mobile validator by adding a function to the validators object at the bottom of the validator script:

var validators = {
    "email": function() { return new RegExp("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$", "mi").test(this.value); },
    "mobile": function() { return  new RegExp("((\\+63)|0)[.\\- ]?9[0-9]{2}[.\\- ]?[0-9]{3}[.\\- ]?[0-9]{4}", "mi").test(this.value); }
};
<input type="text" validate="group" mobile="Invalid mobile, please check for typos." />
<input type="submit" value="Submit" onclick="return validate('group');">