Question: Restrict duplicate words in email regular expression javascript/jquery

Question

Restrict duplicate words in email regular expression javascript/jquery

Answers 1
Added at 2017-01-04 12:01
Tags
Question

I want to restrict duplicate words in an email using regex.

Currently I am using below regex that also restrict 2 consecutive dots (ex: a@gmail..com)

regexp: /A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z][{a-z},0-9](?:[a-z0-9-]*[a-z0-9]){1-2}?)$/i,

Now I want to also restrict duplicate words in email for example :-

abc.xyz@gmail.com.com

It should not accepted second .com .

Answers to

Restrict duplicate words in email regular expression javascript/jquery

nr: #1 dodano: 2017-01-04 12:01

What about:

email="hello.world.world";
email=email.split(".");
fail = email.some((ae,ai)=>email.some((be,bi)=>bi==ai?false:ae==be));
//loop trough all pairs, if they are at the same index skip ( we dont want to check email[0]==email[0]), else compare, if same fail.
if(fail){alert("Wrong email");}
Source Show
◀ Wstecz