DEV Community

Clever Cottonmouth
Clever Cottonmouth

Posted on

EMAIL VALIDATION

`const regex = /\S+@\S+.\S+/

console.log(regex.test("miraj@gmailcom"))

const data =/[a-zA-Z0-9._-]{3,}@[a-zA-Z0-9.-]{3,}.[a-zA-Z]{2,4}/

const email ='mirajhadish49@gmail.com'

console.log(email.match(data)? 'yes':'no');`

Top comments (3)

Collapse
 
franckpaul profile image
Franck Paul

Your regex does not validate account+topic@example.com but this email is a valid email.

You should not try to validate an email this way, see emailregex.com/ for a better approach ;-)

Collapse
 
mirajhad profile image
Clever Cottonmouth

Image description
Hi Franck, this email it can validate

Collapse
 
franckpaul profile image
Franck Paul

The regex validate only the part after the + sign, see regex101.com/r/DlHS02/1

Another valid email as me&@domain.academy is not valid with your regexp (the & character is valid in it).

Another point: the TLD (last part of domain) might be 63 characters long (see data.iana.org/TLD/tlds-alpha-by-do...), you have a set a range to 2-4.

So sometimes your regex give a true answer, but it does not fully validate an email.