Nitin Kabra Nitin Kabra - 1 year ago 54
Javascript Question

Regular Expression for alphabets with spaces

I need help with regular expression. I need a expression which allows only alphabets with space for ex. college name.

I am using :

var regex = /^[a-zA-Z][a-zA-Z\\s]+$/;

but it's not working.

Answer Source

Just add the space to the [ ] :

var regex = /^[a-zA-Z ]*$/;