Jquery Validation for Alphabets

I downloaded jquery validation.js and used it. I need to check for the alphabets for this. For this I need to do in validation.js

My js are like that

categoryname: { required: true, minlength: 2 }, messages: { categoryname: "Enter the category name", 

the above code asks for the required field, and if the field is empty, it will display the following message. here I need to check only for alphabets ........

+6
jquery-validate
source share
2 answers
  jQuery.validator.addMethod("alphanumericspecial", function(value, element) { return this.optional(element) || value == value.match(/^[-a-zA-Z0-9_ ]+$/); }, "Only letters, Numbers & Space/underscore Allowed."); jQuery.validator.addMethod("alpha", function(value, element) { return this.optional(element) || value == value.match(/^[a-zA-Z]+$/); },"Only Characters Allowed."); jQuery.validator.addMethod("alphanumeric", function(value, element) { return this.optional(element) || value == value.match(/^[a-z0-9A-Z#]+$/); },"Only Characters, Numbers & Hash Allowed."); 

U can easily create features like this.

+13
source share

You will need to add an additional method to the validation library, for example:

 $.validator.addMethod("alpha", function(value,element) { return this.optional(element) || /^[a-zA-Z]$/i.test(value); }, "Alphabets only"); 

You can then add it to your validation rules.

Otherwise, you can define the general "regexp" rule as described in this.

+2
source share

All Articles