Reputation: 1817
I only want to allow a-z, A-Z and space in between characters. For this I am using following regex, problem is that it allows the leading and trailing spaces also. Can this be adjusted to not allow leading or trailing white space.
[a-zA-Z\\ \\\']*
examples
'prince charles' should pass
' prince charles' should fail due to leading whitespace
'prince charles ' should fail due to trailing whitespace
Upvotes: 1
Views: 1469
Reputation: 213203
To dis-allow leading and trailing whitespace, you can use:
^[a-zA-Z](?:[a-zA-Z ]*[a-zA-Z])?$
Upvotes: 3