How would one create a data annotation that only allows string that either have letters and numbers or letters only.
Basically disallow number only strings.
Right now, I have a letter only validation and I can't find out how to also allow numbers IF there are letters present in the string.
[RegularExpression(@"^[a-zA-Z]+$", ErrorMessage = "No numbers allowed in the sequence.")]
Thanks!
EDIT - Found a solution!
Basicall:
[0-9]*[A-z ]+[0-9]*
This regex works ALMOST perfectly...
It catches an error if the users enters a number-only string, but... If he adds a single space, he can get away with the string.
To prevent that little error, I simply catch any empty spaces in my POST method from my controller and add an error to the ModelState.
Thanks to @PhillipBetts for the Regex 101 link, which helped me solve this problem!