用户名不能包含重复下划线或句点可以以下划线开头 [英] Username cannot contain repeating underscore or period can start with underscore

查看:164
本文介绍了用户名不能包含重复下划线或句点可以以下划线开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

建议用户名的正则表达式,它接受允许小写,大写,数字和下划线的输入。用户名可以以字母或下划线开头。下划线不得位于字符串的末尾。我不希望用户名包括两个连续的下划线。



我尝试过:



[_a-zA-Z0-9] [a-zA-Z0-9] + _?[a-zA-Z0-9] +



但是用户名失败的问题a_9

suggest an regex for username which takes input that allows lower case, upper case, numbers, and underscores. The username can start with alphabets or underscore. The underscore must not be at the end of the string. I do not want the username to include two consecutive underscores.

What I have tried:

[_a-zA-Z0-9][a-zA-Z0-9]+_?[a-zA-Z0-9]+

But the problem it fails for the username a_9

推荐答案

您需要在第二组中包含下划线字符。您可以在 RegExr:Learn,Build,&测试RegEx [ ^ ]。
You need to include the underscore character in the second group. You can try different patterns at RegExr: Learn, Build, & Test RegEx[^].


使用下面的最后一个链接查看您的RegEx的漂亮图表,您将了解有什么问题。

您确定您的约束吗?

这将使RefEx成为可能非常复杂。

如果用户名是1个字符,会有什么约束?是允许为'_'吗?

'_a_b_c_d_e'似乎合法,但您的RegEx不接受它。



只是几个帮助构建和调试RegEx的有趣链接。

以下是RegEx文档的链接:

perlre - perldoc.perl.org [ ^ ]

以下是帮助构建RegEx并调试它们的工具的链接:

.NET Regex测试员 - 正则表达式风暴 [ ^ ]

Expresso正则表达式工具 [ ^ ]

RegExr:Learn,Build,&测试RegEx [ ^ ]

此节目RegEx是一个很好的图表,它非常有助于理解RegEx的作用:

Debuggex:在线可视正则表达式测试器。 JavaScript,Python和PCRE。 [ ^ ]
Use the last link below to see a nice graph of your RegEx, you will understand what is wrong.
Are you sure about your constraint ?
It will make the RefEx pretty complicated.
What constraint apply if user name is 1 char? is it allowed to be '_' ?
'_a_b_c_d_e' seems legal, but your RegEx will not accept it.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]


这篇关于用户名不能包含重复下划线或句点可以以下划线开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆