开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜