Raj Kumar Boddu Raj Kumar Boddu -3 years ago 46
Javascript Question

Regex which allows alphabets and spaces combination but not only spaces

I want to know the regular expression which allows the combination of alphabets and space but it shouldn't allow only the spaces.

I have searched and read all the articles and found the expression /^[a-zA-Z\s]*$/ which allows only spaces also along with the combination of alphabets and space.

Thanks in advance.

Answer Source

Make your expression require one alphabet and then the additional alphabets and spaces are optional:

/^[A-Za-z][A-Za-z\s]*$/

Also that \s means any whitespace characters (tabs, newlines, carriage returns etc), not just space.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download