Reputation: 141
I have the following validation expresion on an asp.net web form that allows alphanumeric characters, spaces,at least one alpha character, and a minimum of 3 characters and a maximum of 20: ValidationExpression="(?!^[0-9]$)(?!^[a-zA-Z]$)^([a-zA-Z0-9 _]{3,20})$"
Now I have been asked to allow hyphens and apostraphes but no other special characters.
How can I implement this in my current validation?
Upvotes: 0
Views: 142
Reputation: 627219
This (?!^[0-9'-]$)(?!^[a-zA-Z'-]$)^([a-zA-Z0-9 _'-]{3,20})$
?
Well, the main trick here is that -
sign should be placed at the end of the character group for it to be parsed as a literal hyphen.
Upvotes: 1