-1

Trying to create custom email validation for below rules

  1. The local part can be up to 64 characters in length and consist of any combination of alphabetic characters, digits, or any of the following special characters: ! # $ % & ‘ * + – / = ? ^ _ ` . { | } ~
  2. The period character (".") is valid for the local part subject to the following restrictions: A. it is not the first or last character B. two or more consecutive periods
  3. top level domains cannot be all numeric
  4. hyphens cannot be the first or last character

^([a-zA-Z0-9!#\$%&‘*+/\=\?\^_'`}{\|~-][.]?)@[a-zA-Z0-9]+(?:(.)\0?(?!\1))[a-zA-Z0-9-]*[a-zA-Z0-9]+(.[a-zA-Z0-9]{2,63})+$

First part (before @ )is good but unable to place
  • two or more consecutive periods
  • hyphens cannot be the first or last character

    for example

  • leela.test@te-st.gm-ail.com(correct)
  • leela.test@te-st..gm-ail.com(incorrect)
  • leela.test@.te-st.gm-ail.com(incorrect)
  • leela.test@-te-st.gm-ail-.com(incorrect)
  • leela.test@.te-st.gm-ail-.com(incorrect)
  • leela.test@test.gmail.com(correct)
  • leela@gmail.com(correct)
  • leela@test.gm-ail.com(correct)

Please help.

Prak
  • 815
  • 7
  • 18
  • There are already a number of email regexes here, but here is an attempt at your specific case: https://regex101.com/r/uQMH2p/1 – Gary Feb 15 '19 at 19:50

1 Answers1

0
[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*\@[a-zA-Z0-9]+\-[A-Za-z0-9]+\.[a-zA-Z0-9]+\-[A-Za-z0-9]+\.com