Javascript: Email Validator

October 3, 2008
by Julian

Problem: email should allow +/- characters in user, – in domain.
dash (-) should be allowed anywhere in an email address or domain.
plus (+) is allowed in the username (many people use this for categorization, especially at gmail)

Solution :

var regex = new RegExp("^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$","i");

This will validated also emails like: username1+username2@gmail-domain.co.uk

This entry was posted in Javascript and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">