电子邮件格式如下:domain_part.com @ local_part
Local_part & domain_part不应以特殊字符( @#&()*,./{}<>^%[]~`!$=|;:?)开头或结尾包括连字符(-)
Local_part & domain_part只能在中间包含上述特殊字符(#$%&*- etc)。
local_part的长度限制分别为64和domain_part is 255 characters。
domain_part不能包含所有数字
发布于 2018-07-13 23:55:29
更新于2018年7月27日
^(?![.!#$%&'*+/=?^_`{|}~-])(?:[a-zA-Z0-9]|(?:(?:([.])(?!\1)|[!#$%&'*+/=?^_`{|}~-]))(?!@)){1,64}@(?=.{1,255}$)(?!\d+$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$
https://regex101.com/r/dxCmEn/1
^ # BOS
(?! [.!#$%&'*+/=?^_`{|}~-] ) # Local does not start with one of these
(?: # Local
[a-zA-Z0-9]
|
# Special chars
# Local does not end with one of these
(?:
# Option 1
(?:
( [.] ) # (1), Not a consecutive special char (specific), add more
(?! \1 ) #
| # or,
[!#$%&'*+/=?^_`{|}~-] # One of these other special chars, remove from here
)
# Option 2
# | ( [.!#$%&'*+/=?^_`{|}~-] ) # (1) Not a consecutive same special char
# (?! \1 )
# Option 3
# | [.!#$%&'*+/=?^_`{|}~-] # Not a consecutive any special char
# (?! [.!#$%&'*+/=?^_`{|}~-] )
# Option 4, Original
# | [.!#$%&'*+/=?^_`{|}~-] # Any special char is OK
#
)
(?! @ )
){1,64} # 1 to 64 local characters
@
(?= .{1,255} $ ) # 1 to 255 domain characters
(?! \d+ $ ) # Domain must not contain all numbers
[a-zA-Z0-9] # Domain
(?:
[a-zA-Z0-9-]{0,61}
[a-zA-Z0-9]
)?
(?:
\.
[a-zA-Z0-9]
(?:
[a-zA-Z0-9-]{0,61}
[a-zA-Z0-9]
)?
)*
$ # EOS
发布于 2018-07-13 23:44:01
因此,根据您有限的描述,您似乎在寻找like this?
下面是模式:^(?<localpart>[^-].*[^-])@(?<domainpart>[^-].*[^-])\..{2,3}$
它将它们保存到命名捕获组中,并假定localpart和domainpart都至少包含2个字符(它们应该包含)。这两个部分都不允许以-
开头或结尾。
还有其他要求吗?或者这几乎涵盖了它吗?
https://stackoverflow.com/questions/51327304
复制相似问题