monda monda - 7 months ago 42
Javascript Question

Jquery Validation: allow only alphabets and spaces

My validation accepts only alphabets . i want allow spaces as well .

$.validator.addMethod("alpha", function(value, element) {
return this.optional(element) || value == value.match(/^[a-zA-Z]+$/);
});


what change need to be done here ?

Answer

Instead of the below regex:

/^[a-zA-Z]+$/

Use this:

/^[a-zA-Z\s]+$/

This will also take the space.

Comments