Restrict duplicate words in email regular expression javascript/jquery

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 .


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

Answers to Restrict duplicate words in email regular expression javascript/jquery ( 1 )

  1. 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");}
    

Leave a reply to - Restrict duplicate words in email regular expression javascript/jquery

◀ Go back