RegEx for pattern in c#
I am still learning RegEx so I need some help on this one.
Rules are as below:
- Min/Max Length of string: 1-5
- String has to be a whole word
- String can contain: A-Z and/or a-z and/or 0-9 or combination of both only 开发者_如何学运维(e.g. _ - . * are not allowed)
Examples:
12345 – allowed
Os342 – allowed
2O3d3 – allowed
3sdfds dsfsdf – not allowed
Sdfdf.sdfdf –now allowed
What about:
string input = "12345";
bool match = Regex.IsMatch(input, "^[a-z0-9]{1,5}$", RegexOptions.IgnoreCase);
How about
^[A-Za-z0-9]{1,5}$
^[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 range
精彩评论