Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
135
rated 0 times [  138] [ 3]  / answers: 1 / hits: 94622  / 10 Years ago, tue, april 1, 2014, 12:00:00

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 needs to be done here?


More From » jquery

 Answers
45

Instead of the below regex:



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


Use this:



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


This will also take the space.


[#71688] Saturday, March 29, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
levidaylonj

Total Points: 392
Total Questions: 100
Total Answers: 112

Location: Bahrain
Member since Fri, Sep 16, 2022
2 Years ago
;