Skip to content Skip to sidebar Skip to footer

Validation For Inputs In Jquery Using Regex

i was creating a simple form which has two inputs Name and Email on submit if i write numbers in name input then it will show number is not allowed message as like required message

Solution 1:

I dont know if I understand your question, but using the validate plugin, you can create additional validation rules and use regex as the validation parameter. I'm using this code:

jQuery.validator.addMethod("regex", function(value, element, regexp) {
    var re = newRegExp(regexp);
    returnthis.optional(element) || re.test(value);
},"Invalid Data");

And input:

<input required="" data-rule-regex="^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$" title="Enter a valid IPV4" name="ip"type="text">

Post a Comment for "Validation For Inputs In Jquery Using Regex"