Reputation: 1052
I'm making a dictionary application and need an regexp that check if the users input is only letters and spaces eventually. This is probably the most easiest regexp but i can figure it out. So far i have
/^[\w\D]$/
which is not working :/
sorry guys, forgot to mention that will need to exclude all spec characters also.
Upvotes: 1
Views: 102
Reputation: 382474
You seem to want this one :
/^[\u00C0-\u1FFF\u2C00-\uD7FFa-zA-Z\s]+$/
It should accept only characters (including "not English" characters like the ones you have in Spanish and Cyrillic) as well as spaces, but exclude digits.
Example :
/^[\u00C0-\u1FFF\u2C00-\uD7FFa-zA-Z\s]+$/.test("переполнения стека")
returns true
Upvotes: 4
Reputation:
To match a string consisting only of letters and whitespace characters, you can use:
/^[a-zA-Z\s]+$/
Upvotes: 1
Reputation: 888243
Your regular expression matches exactly one such character.
You can add the +
modifier to match one or more characters.
Upvotes: 1