I want to construct a regular expression where .
is not allowed as the last and first character of the email address (example: .abc.@gmail.com
should not be accepted). Also, I have another requirement that ..
2 consecutives periods should not be allowed anywhere in the email address (example: abc...def@gmail.com
).
The regular expression that I am currently using is: let regEx = new RegExp(/^[a-zA-Z0-9+_.-]+@(\[(\d{1,3}\.)(([a-zA-Z\d-]+\.)+))([a-zA-Z]{2,15}|\d{1,3})(\]?)/);
.
Can I get some help in modifying the above regular expression to fulfill my requirement?
PS: I have very little knowledge on regular expressions.
Adding your 2 new requirements we can try:
^(?!.*\.\.)[\p{L}\p{N}\s,_-][\p{L}\p{N}\s,._-]*[\p{L}\p{N}\s,_-]$
Explanation:
^ 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.