Ian Vink
Ian Vink

Reputation: 68780

Email RegEx which supports e-mail "+"

I've been trying to create a reg ex that supports gmail's "plus":

[email protected]

^[\w-.]+@([\w-]+.)+[\w-]{2,4}$

How do I allow the + ?

Upvotes: 0

Views: 58

Answers (2)

There is only one truly reliable way to store only real email addresses in your database: send a confirmation mail with a confirmation link. [email protected] will pass all checks, but is very probably not a real address.

To catch typos by the user, and thus prevent unnecessary action by your server, just have him/her enter the address twice, and compare the inputs.

Upvotes: 0

Avinash Raj
Avinash Raj

Reputation: 174766

As others said, it's so hard to validate an email-address exactly. But we could do a low level validation. For validation, you don't need to capture anything. So turn the capturing group in your regex to non-capturing group.

^[\w-.+]+@(?:[\w-]+.)+[\w-]{2,4}$

DEMO

Upvotes: 1

Related Questions