Question

Problem:-I want to validate an email id text box..I want to block Gmail id users

Eg:-

  • abcd@yahoo.com =>Ok
  • abcd@xmail.com =>Ok
  • abcd@hotmail.com =>Ok
  • abcd@gmail.com =>Not Ok

If any user entering Gmail id in the text box..the error msg will appear..??

already tried using

\w+([-+.']\w+)*@(?:gmail).com

But it Used for selecting only Gmail ids..I want negation of this..

Était-ce utile?

La solution

Change (?: ) to (?! ) to match if content of ( ) is not present:

\w+([-+.']\w+)*@(?!gmail).com

This will not match abcd@gmail.com, but will fail also on abcd@yahoo.com because no other characters allowed between @ and .com

To keep gmail.com blocked and to allow other domains change pattern to

\w+([-+.']\w+)*@((?!gmail\.com).*)

Note that when you have [-+.'] you tell to allow -,+,. and ' in the email address. Minus and dots are allowed but not plus and apostrophe.

So, finally

\w+([-.]\w+)*@((?!gmail\.com).*)

Autres conseils

I think you can use negation of that

\w+([-+.']\w+)*@(?:gmail).com

In an if block check the email using this and take the negation..I think it will work

Try below regular expression:

\b[\w\.-]+@((?!gmail).)[\w\.-]+\.\w{2,4}\b
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top