Reputation: 171
I've a textbox in an ASP.NET application, for which I need to use a regular expression to validate the user input string. Requirements for regex are -
Matches:
Non Matches:
Upvotes: 2
Views: 15619
Reputation: 13641
Assuming there must be either one or two 'words' (i.e. sequences of non-space characters)
"\s*\S+(\s\S+)?\s*"
Change \S
to [A-Za-z]
if you want to allow only letters.
Upvotes: 3
Reputation: 6517
Maybe this one will do?
\s*\S+?\s?\S*\s*
Edit: Its a server-encoded regex, meaning that you might need to remove one of those escaping slashes.
Upvotes: 0