Reputation: 9691
I'm looking for a regexp to see if a string contains any special characters, numbers or anything else but letters.
For example I have a string "This is a 5 string #"
. Now I would need a regexp to see if this string contains any special characters like #
or numbers like 5
.
I'm not familiar with using regexp approaches.
Upvotes: 1
Views: 6216
Reputation: 123367
you can use .test()
method
if ("This is a 5 string #".test(/[^a-z]/i)) { ... }
this will find if some symbols different from a-z and A-Z are inside the string. Note also that this regexp won't accept accented letters. in that case you will need a more refined regexp like
/[^a-zA-Z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF]/
see a unicode table to choose what symbols are acceptable in your string
Upvotes: 3
Reputation: 10260
The basics you want is something like /^[a-zA-Z]+$/
this will tell you if your string as any charachters of a to z upper and lowercase.
There are tons off resources online to learn more about regex, a good resource is http://www.regular-expressions.info/reference.html
Upvotes: 1