Email Address Validation with Regex

Need to validate email addresses on your site? Use this simple regex test to check for valid email addresses.

All companies and site owners can relate to performing email address validation to verify an email address for new users, mailing lists, lead generation, etc. Email addresses are often the most popular personal info field shared by consumers and online users.

As users funnel through your site, it's important to validate all user inputs, especially the email address.

What's The Problem With Trusting User Emails?
Email Address Validation Regex

You have a sign up form, contact form, order form, newsletter, or other area of your site where users can input email address. You want to validate that users are submitting real email addresses to prevent bounces, fake users, and similar issues from poor data quality.

Since many companies do not perform any type of validation for email addresses, online users are very accustomed to entering a fake email address whenever prompted for their personal information. These users typically do not wanted to be contacted or receive SPAM, or sometimes the reasons are nefarious, such as creating fake accounts.

What's The Solution To Verifying Email Addresses?

Quickly implement basic email address validation on your site with a regular expression.

Using email validation regex, you can quickly determine if an email address is properly formatted. So if a user enters a random string such as "xkhalfuagh", the regex test would detect this as improperly formatted. Email Validation Regex tests are an easy solution to deploy for any programming language. To perform even more checks, view our best practices guide to email verification.

Email Address Regular Expression for Multiple Languages

Each of the regex patterns listed below will provide email validation for the respective coding language.

General Regex
[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}
PHP
/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD
Bonus PHP Validation
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
	echo("$email is a valid email address");
} else {
	echo("$email is not a valid email address");
}
.NET
^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
Ruby
/\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
Python
r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
How To Bring Email Address Validation to the Next Level

While using regular expressions for email validation will provide a quick solution to bogus user inputs, it would still be possible for a bogus email such as "axhbdaeiandlayadakceamhauldal@hotmail.com" to be entered by a user and pass the regex test. So how can we enforce even greater filtering for email addresses?

Using a web service API is ultimately the best solution to validating email addresses in real-time. If you are a developer, I'm sure you are already pondering why can't I make a system on my own? Well the truth is, email verification is quite a difficult feat as many mail services do not play nicely with the verification process. It's much easier to tap directly into an existing service.

What Are the Benefits of an Email Verification API?

Query individual or batch email addresses in real-time to get an accurate insight into the email address.

  • Determine if the email address is valid
  • Is it a spamtrap?
  • Is it a honeypot or frequent complainer?
  • Has the email address recently been involved in fraud?
  • Does the email belong to a disposable or temporary email service commonly used for abuse?

Ultimately getting real-time accurate results for each email address is a cost-effective solution to verifying email addresses that can scale as you grow.

IPQualityScore provides the most trusted Email Address Validation service. Do you have less than 5,000 emails that need to be scored per month? Excellent, you qualify to use our service for free, up to 5K lookups per month.

Do you have greater volume? IPQS provides email verification to the internet's most popular sites. Take advantage of that same enterprise level accuracy with 10x less costs than similar providers and packages starting at $20 per month.

Test an Email Address

Want to test an email right now? Use our free Email Verifier to test any address through a web form.

API Lookup Access

Easy API Lookups

Threat & Abuse Network

Largest Threat & Abuse Network

Fraud Prevention Detection

Industry Leading Fraud Prevention

Ready to eliminate fraud?

Start fighting fraud in minutes!

Questions? Call us at (800) 713-2618

Schedule a Demo Sign Up »

Get Started with 5,000 Free Lookups Per Month!