-1

What I want to do is to validate an email address with exact gmail or yahoo word and I have tried the following but failed:

/^[a-z0-9._%+-]+@[^gmail$.-]+\.[a-z]{2,}$/

suppose if anyone mistakenly tried to sign up using example@gmal.com or example@mail.com or example@yaho.com or something like that. How can I validate that??

Fuad9
  • 353
  • 1
  • 3
  • 19
  • Why Gmail specifically? What are you trying to achieve? There are lots of edge-cases such googlemail.com vs gmail.com – Jakg Sep 10 '20 at 14:11

1 Answers1

1

For regex to validate email you can refer this.

If you want a simple validator to allow only email addresses that contains @gmail as part of it and allow only letters,numbers,dot and underscores in user name, you can use below regex.

^[a-z0-9._]+@gmail\.[a-z]{2,}$

Demo

Liju
  • 2,273
  • 3
  • 6
  • 21