[英]Regular expression to not accept . at the end of the email address in React
我想构造一个正则表达式 where .
不允许作为 email 地址的最后一个和第一个字符(例如: .abc.@gmail.com
不应被接受)。 此外,我还有另一个要求,即..
地址中的任何地方都不允许有 2 个连续的周期(例如: abc...def@gmail.com
)。
我目前使用的正则表达式是: let regEx = new RegExp(/^[a-zA-Z0-9+_.-]+@(\[(\d{1,3}\.)(([a-zA-Z\d-]+\.)+))([a-zA-Z]{2,15}|\d{1,3})(\]?)/);
.
我可以在修改上述正则表达式以满足我的要求方面获得一些帮助吗?
PS:我对正则表达式知之甚少。
添加您的 2 个新要求,我们可以尝试:
^(?!.*\.\.)[\p{L}\p{N}\s,_-][\p{L}\p{N}\s,._-]*[\p{L}\p{N}\s,_-]$
解释:
^ from the start of the email
(?!.*\.\.) no two or more consecutive dots
[\p{L}\p{N}\s,_-] first character is not dot
[\p{L}\p{N}\s,._-]* zero or more allowed characters, including dot
[\p{L}\p{N}\s,_-] last character is not dot
$ end of the email
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.