Gavin
Gavin

Reputation: 7954

How can I add support for a + (plus sign) in this email validation regex?

This is a regular expression I found online that seems to do a great job at simple email address validation. The problem is it doesn't allow + in the email, like [email protected]. I'm not great at regex, so how can I add support for a + without breaking the whole thing?

var regex = new RegExp( /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i );

Upvotes: 3

Views: 4250

Answers (2)

user2643679
user2643679

Reputation: 705

([+\w0-9._-]+@[\w0-9._-]+\.[\w0-9_-]+)

Upvotes: 0

Michael Ward
Michael Ward

Reputation: 526

Change the second [\w-]+ to [+\w-]+

Upvotes: 6

Related Questions