I need a regular expression to check a string should contain only letters and space.No other character other than letter [A-Z] and space are allowed.
Please help.
I need a regular expression to check a string should contain only letters and
Share
The complete regex looks like this
You can simply create a character class and put the characters in that you want to allow:
if you want to allow also lower case letters then use
or use the i (IgnoreCase) option
So your character class matches 1 character. you want to repeat it to match more than one character.
+would be at least one character, where*would additionally match 0 charactersAs last step you need to ensure that the complete string is matched, you can do this using anchors.
^matches the beginning of the string$matches the end of the string (or a newline if you use the m (multiline) option