[英]Email Address Validation Regex
So I want to set up an Email Address Validation Regex with the following constraints...所以我想设置一个具有以下约束的 Email 地址验证正则表达式......
reference: α
@ β
.参考: α
@ β
。 γ
for α
对于α
1) Only contain az
0-9
.
1) 仅包含az
0-9
.
-
_
-
_
2) Contain between 1 and 30 chars (inclusive) 2) 包含 1 到 30 个字符(含)
3) Can't start or end with .
3) 不能以 . 开头或结尾.
-
_
-
_
4) Can't have 2 consecutive symbols (out of .
-
_
) in it 4) 不能有 2 个连续的符号(超出.
-
_
)
for β
对于β
1) Only contain az
0-9
-
1) 只包含az
0-9
-
2) Contain between 2 and 14 chars (inclusive) 2) 包含 2 到 14 个字符(含)
3) Can't start or end with -
3) 不能以-
开头或结尾
4) Can't have 2 consecutive -
in it 4) 不能有 2 个连续的-
在里面
for γ
对于γ
1) Only contain az
1) 只包含az
2) Contain between 2 and 4 chars (inclusive) 2) 包含 2 到 4 个字符(含)
=========================================================================== ==================================================== ==========================
The first two constraints of each are easy to implement, So I have done it, as follows每个的前两个约束很容易实现,所以我做了,如下([a-z0-9.\-_]{1,30})@([a-z0-9\-]{2,14}).([az]{2,4})
Can anyone help me with (2) and (3) of α
and β
谁能帮我解决α
和β
的(2)和(3)
You may use您可以使用
/^(?=[^@]{1,30}@)[a-z0-9]+(?:[._-][a-z0-9]+)*@(?=.{2,14}\.[a-z]+$)[a-z0-9]+(?:-[a-z0-9]+)*\.[a-z]{2,4}$/
See the regex demo查看正则表达式演示
Details细节
^
- start of string ^
- 字符串的开头(?=[^@]{1,30}@)
- 1 to 30 chars are allowed before a @
(?=[^@]{1,30}@)
- 在@
之前允许 1 到 30 个字符[a-z0-9]+
- 1+ lowercase letters and digits [a-z0-9]+
- 1+ 小写字母和数字(?:[._-][a-z0-9]+)*
- 0 or more occurrences of .
(?:[._-][a-z0-9]+)*
- 0 次或多次出现.
, _
or -
followed with 1+ lowercase letters or digits , _
或-
后跟 1+ 小写字母或数字@
- a @
char @
- 一个@
字符(?=.{2,14}\.[az]+$)
- immediately to the right, there must be 2 to 14 chars, then .
(?=.{2,14}\.[az]+$)
- 紧靠右边,必须有 2 到 14 个字符,然后.
and 1+ lowercase letters till the end of string和 1+ 个小写字母直到字符串结尾[a-z0-9]+(?:-[a-z0-9]+)*
- 1+ lowercase letters and digits and then 0 or more occurrences of a hyphen followed with 1+ lowercase letters or digits [a-z0-9]+(?:-[a-z0-9]+)*
- 1+ 小写字母和数字,然后出现 0 次或多次连字符,后跟 1+ 小写字母或数字\.
- a dot - 一个点[az]{2,4}
- two to four lowercase letters [az]{2,4}
- 两到四个小写字母$
- end of string. $
- 字符串结束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.