Home > other >  Regex to match a email to contains at least one character
Regex to match a email to contains at least one character

Time:11-18

I need a regex to match an email which:

  • must contain at least one alphabet
  • can contain digits
  • can contain _ and ..
  • must be an email format (i.e., contains @something.something)

I have found this

^((?=.*[a-zA-Z])\w ([\.-]?\w )*)@\w ([\.-]?\w )*(\.\w{2,3}) $

but it is accepting [email protected], which is invalid according to my specs

CodePudding user response:

As per your specs I've created the following Regex for you

^\w*[A-Za-z] (?:([._]?\w )*)\@[A-Za-z]\w*[-]?\w \.[A-Za-z]{1,}?(\.?[A-Za-z] )$

It should work for all your edge cases, and it also covers all the domain names including with - like former-player and also .co.uk and such

  • Related