Restrict duplicate words in email regular expression javascript/jquery


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

Currently I am using below regex that also restrict 2 consecutive dots (ex:

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 :-

It should not accepted second .com .

Show source
| javascript   | jquery   | regex   2017-01-04 12:01 1 Answers

Answers ( 1 )

  1. 2017-01-04 12:01

    What about:

    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");}
◀ Go back