Quantcast
Viewing latest article 12
Browse Latest Browse All 20

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

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

<inputtype="text"validate="group"regular="Invalid mobile, please check for typos."validExpress="((\+63)|0)[.\- ]?9[0-9]{2}[.\- ]?[0-9]{3}[.\- ]?[0-9]{4}"/><inputtype="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() { returnnew RegExp("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$", "mi").test(this.value); },"mobile": function() { returnnew RegExp("((\\+63)|0)[.\\- ]?9[0-9]{2}[.\\- ]?[0-9]{3}[.\\- ]?[0-9]{4}", "mi").test(this.value); }
};
<inputtype="text"validate="group"mobile="Invalid mobile, please check for typos."/><inputtype="submit"value="Submit"onclick="return validate('group');">

Viewing latest article 12
Browse Latest Browse All 20

Trending Articles