I'm using the validate plugin from http://bassistance.de/jquery-plugins/jquery-plugin-validation/
What i'm trying to find is a way to make some of my form fields accept letters only, no numbers, special chars etc...
Any idea people ? Thanks a lot.
Validation in JQuery: Using JQuery, a form is validated on the client-side before it is submitted to the server, hence saves the time and reduce the load on the server. Form Validation means to validate or check whether all the values are filled correctly or not.
Simply add a custom validator, and use it like this:
jQuery.validator.addMethod("accept", function(value, element, param) {
return value.match(new RegExp("." + param + "$"));
});
Only numbers:
rules: {
field: { accept: "[0-9]+" }
}
Only letters
rules: {
field: { accept: "[a-zA-Z]+" }
}
A small change.
jQuery.validator.addMethod("accept", function(value, element, param) {
return value.match(new RegExp("^" + param + "$"));
});
Because that way it was accepting expressions like "#abc".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With