Reputation: 2423
I have a Regex to not allow spaces and some special chars., but the validation fires even when Uppercase letters are entered.
[RegularExpression(@"^[^<>.,?;:'()!~%-_@#%/*""\s]+$")]
public string FirstName { get; set; }
Upvotes: 2
Views: 6776
Reputation:
You need to remove the -
(minus sign). %-_
means between %
(char code 37) and _
(char code 95) which includes upper case characters.
If you want to exclude the minus symbol, then you need to escape it using \-
.
The attribute should be
[RegularExpression(@"^[^<>.,?;:'()!~%\-_@#/*""\s]+$")]
public string FirstName { get; set; }
Upvotes: 6