Reputation: 68780
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
Reputation: 3190
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
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}$
Upvotes: 1