Reputation: 13199
I am still learning RegEx so I need some help on this one.
Rules are as below:
Examples:
12345 – allowed
Os342 – allowed
2O3d3 – allowed
3sdfds dsfsdf – not allowed
Sdfdf.sdfdf –now allowed
Upvotes: 1
Views: 110
Reputation: 38860
^[a-zA-Z0-9]{1,5}$
[a-zA-Z0-9]
specifies the ranges allowed^
specifies start of string$
specifies end of string{1,5}
indicates minimum and maximum number of characters for the rangeUpvotes: 3
Reputation: 57926
What about:
string input = "12345";
bool match = Regex.IsMatch(input, "^[a-z0-9]{1,5}$", RegexOptions.IgnoreCase);
Upvotes: 3