Reputation: 5664
Can anyone please tell me jquery validation, that should validate only alphabets, i.e)
abcde - valid
12344 - not valid
ancd12 - not valid
asng$e - not valid etc
this code will not work for above conditions.
alphabet: function(value, element, param) {
return this.optional(element) || value.match(/[a-z]/gi);
}
Upvotes: 1
Views: 1350
Reputation: 6086
use validation plugin method written specifically for this purpose, found in the validation plugin additional-methods.js
jQuery.validator.addMethod("lettersonly", function(value, element) {
return this.optional(element) || /^[a-z]+$/i.test(value);
}, "Letters only please");
Upvotes: 1
Reputation: 94319
alphabet: function(value, element, param) {
return /^[A-z]+$/.test(value);
}
Upvotes: 1