Reputation: 13620
It's very simple:
Match match = Regex.Match(username, @"/^[a-z0-9_-]{3,16}$/", RegexOptions.IgnoreCase);
if (!match.Success)
throw new Exception("Manglende/ugyldig brukernavn.");
But no matter what it fails that test. What am I forgetting?
Upvotes: 2
Views: 71
Reputation: 179717
Don't put slashes around the regex:
@"^[a-z0-9_-]{3,16}$"
The slashes are typically used in other languages to delimit a regex. But in C#, the entire string is the pattern so additional delimiters are not required.
Upvotes: 7