Skip to content Skip to sidebar Skip to footer

Allow Only Letters And Spaces - Jquery Validation Plugin

I am validating a text field to allow only letters and spaces. This is the method I am using: jQuery.validator.addMethod('lettersonly', function(value, element) { return this.

Solution 1:

The regular expression is:

^[a-z\s]*$

LIVE DEMO

Solution 2:

jQuery.validator.addMethod("lettersonly", function(value, element) { 
    returnthis.optional(element) || /^[a-zA-Z\s]*$/.test(value);
},"Please enter only letters");

replace this : /^[a-z\s]+$/i

by this :/^[a-zA-Z\s]*$/

I checked It works.

Post a Comment for "Allow Only Letters And Spaces - Jquery Validation Plugin"