正则表达式 – 需要正则表达式来验证用户名
发布时间:2020-12-14 02:29:14 所属栏目:百科 来源:网络整理
导读:需要一个正则表达式来验证用户名: 应该允许尾随空格但不允许字符之间的空格 必须至少包含一个字母,可能包含字母和数字 最多7-15个字符(字母数字) 不能包含特殊字符 允许下划线 不知道该怎么做.任何帮助表示赞赏.谢谢. 这是我使用的,但它允许字符之间的空格
需要一个正则表达式来验证用户名:
>应该允许尾随空格但不允许字符之间的空格 不知道该怎么做.任何帮助表示赞赏.谢谢. 这是我使用的,但它允许字符之间的空格 "(?=.*[a-zA-Z])[a-zA-Z0-9_]{1}[_a-zA-Z0-9s]{6,14}" 示例:用户名
试试这个:
foundMatch = Regex.IsMatch(subjectString,@"^(?=.*[a-z])w{7,15}s*$",RegexOptions.IgnoreCase); 也允许使用_,因为您在尝试时允许这样做. 所以基本上我使用三个规则.一个检查是否至少存在一个字母. 分解: " ^ # Assert position at the beginning of the string (?= # Assert that the regex below can be matched,starting at this position (positive lookahead) . # Match any single character that is not a line break character * # Between zero and unlimited times,as many times as possible,giving back as needed (greedy) [a-z] # Match a single character in the range between “a” and “z” ) w # Match a single character that is a “word character” (letters,digits,etc.) {7,15} # Between 7 and 15 times,giving back as needed (greedy) s # Match a single character that is a “whitespace character” (spaces,tabs,line breaks,etc.) * # Between zero and unlimited times,giving back as needed (greedy) $ # Assert position at the end of the string (or before the line break at the end of the string,if any) " (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- oracle11G EM ORA-28001: the password has expired (DBD E
- 数据结构作业21—B-树、B+树与哈希查找(选择题)
- 为什么在我的xcode项目文件中恢复了引用?
- Flex4系列一:myeclipse8.5 轻松集成 Flex4 插件(图解)
- 正则表达式 – 正则表达式的什么样的风格是grep?
- vue自定义移动端touch事件之点击、滑动、长按事件
- (七)swift新建首页(整合TabBar和NavigationBar)
- 使用sqldf将巨大的csv文件读入R中,但是sqlite文件需要两倍的
- 理解 Flex itemRenderer - 第 5 部分: 效率
- 正则表达式 – gVim查找/替换为计数器
推荐文章
站长推荐
热点阅读