Skip to content

Instantly share code, notes, and snippets.

Email Validation with Regex

The following regular expression validates a user's input to check that it has all the components of a valid email address.

^([a-z0-9_.-]+)@([\da-z.-]+).([a-z.]{2,6})$

Summary

This regex checks to see if the input before the "@" contains numbers or letters, has a period or hyphen to separate values, then checks for an "@" symbol,then checks for letters for the domain name after the "@", checks that there's a dot after the domain, and lastly checks for another set of letters with a minimum value of 2 and a maximum of 6 letters after the ".".