开发者

Regular Expression : User Name

开发者 https://www.devze.com 2023-01-20 12:17 出处:网络
I\'m trying to create a regular expression for a user name. Her开发者_StackOverflowe are the rules 1) At least 8 characters and at most 50 characters

I'm trying to create a regular expression for a user name.

Her开发者_StackOverflowe are the rules 1) At least 8 characters and at most 50 characters 2) Allows A-Z, a-z, numbers, and any other character except / character.

Thank you, -Tesh


Use

\A[^/]{8,50}\Z

or, in C#:

Regex regexObj = new Regex(@"\A[^/]{8,50}\Z");

The start-and-end-of-string anchors \A and \Z are necessary because otherwise regexObj.IsMatch() would return True even if only a part of the regex would match, and you want the string to match in its entirety.


This should work for you...

[^/]{8,50}

If you want to be more specific about which characters you want to include then you can do something like this instead...

[A-Za-z0-9,\.!@#\$%\^&\*\(\)\-_\+\=]{8,50}

0

精彩评论

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

关注公众号