Skip to content Skip to sidebar Skip to footer

Regex Expression To Match Special Characters And Numbers

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 n

Solution 1:

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

http://unicode.org/charts/


Solution 2:

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


Post a Comment for "Regex Expression To Match Special Characters And Numbers"