需要一个正则表达式来验证用户名:
不知道该怎么做.任何帮助表示赞赏.谢谢.
这是我使用的,但它允许字符之间的空格
"(?=.*[a-zA-Z])[a-zA-Z0-9_]{1}[_a-zA-Z0-9\\s]{6,14}"
Run Code Online (Sandbox Code Playgroud)
示例:用户名用户名中不允许使用空格
尝试这个:
\n\nfoundMatch = Regex.IsMatch(subjectString, @"^(?=.*[a-z])\\w{7,15}\\s*$", RegexOptions.IgnoreCase);\nRun Code Online (Sandbox Code Playgroud)\n\n也允许使用,_因为您在尝试中允许这样做。
所以基本上我使用三个规则。一个用于检查是否至少有一个字母存在。\n另一个用于检查字符串是否仅由字母加 组成_,最后我接受尾随空格和至少 7 个字母,最多 15 个字母。你处于良好的轨道上。坚持下去,你也会在这里回答问题:)
分解:
\n\n "\n^ # Assert position at the beginning of the string\n(?= # Assert that the regex below can be matched, starting at this position (positive lookahead)\n . # Match any single character that is not a line break character\n * # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)\n [a-z] # Match a single character in the range between \xe2\x80\x9ca\xe2\x80\x9d and \xe2\x80\x9cz\xe2\x80\x9d\n)\n\\w # Match a single character that is a \xe2\x80\x9cword character\xe2\x80\x9d (letters, digits, etc.)\n {7,15} # Between 7 and 15 times, as many times as possible, giving back as needed (greedy)\n\\s # Match a single character that is a \xe2\x80\x9cwhitespace character\xe2\x80\x9d (spaces, tabs, line breaks, etc.)\n * # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)\n$ # Assert position at the end of the string (or before the line break at the end of the string, if any)\n"\nRun Code Online (Sandbox Code Playgroud)\n