[英]How can I make regular expression for username that only starts with alphabet?
I'm trying to create a regular expression that will allow only specific usernames我正在尝试创建一个只允许特定用户名的正则表达式
this is what i am doing - ^(?=[a-zA-Z0-9._]{4,10}$)(?..*[_.]{2})[^_.].*[^_.]$
这就是我正在做的 -
^(?=[a-zA-Z0-9._]{4,10}$)(?..*[_.]{2})[^_.].*[^_.]$
This should work for you:这应该适合你:
^(?=[a-zA-Z0-9._]{4,10})[a-zA-Z](?:[a-zA-Z]+_[a-zA-Z0-9]+|[a-zA-Z]+\.[a-zA-Z0-9]+|[a-zA-Z0-9]+)$
If the only problem currently is that it should not start with numbers, you could use one of these patterns that start the match with a char [A-Za-z]
and ends the match with [a-zA-Z0-9]
如果当前唯一的问题是它不应该以数字开头,您可以使用以下模式之一,以 char
[A-Za-z]
开始匹配并以[a-zA-Z0-9]
结束匹配
In the middle there can only be 1 occurrence of either .
在中间只能出现 1 次
.
or _
或
_
^(?=[a-zA-Z0-9._]{4,10}$)(?!.*[_.]{2})[A-Za-z]+(?:[_.][a-zA-Z0-9]+)?$
Or another variation:或另一种变体:
^[a-zA-Z](?=[a-zA-Z0-9._]{3,9}$)[a-zA-Z0-9]*(?:[._][a-zA-Z0-9]*)?[a-zA-Z0-9]$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.