My validation accepts only alphabets. I want allow spaces as well.
JavaScript
x
4
1
$.validator.addMethod("alpha", function(value, element) {
2
return this.optional(element) || value == value.match(/^[a-zA-Z]+$/);
3
});
4
What change needs to be done here?
Advertisement
Answer
Instead of the below regex:
JavaScript
1
2
1
/^[a-zA-Z]+$/
2
Use this:
JavaScript
1
2
1
/^[a-zA-Zs]+$/
2
This will also take the space.