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?
Instead of the below regex:
/^[a-zA-Z]+$/
Use this:
/^[a-zA-Z\s]+$/
This will also take the space.
Just leave a space or use \s in your regex:
$.validator.addMethod("alpha", function(value, element) {
    return this.optional(element) || value == value.match(/^[a-zA-Z\s]+$/);
    // --                                    or leave a space here ^^
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With