We’re improving Formula Genius. We’re redesigning the app and fixing issues along the way. Sorry for any disruption, and thank you for your patience.
Regex intermediate

How to Validate Email Addresses with Regex?

Ensuring that email addresses are correctly formatted is crucial for data integrity. This regex pattern helps you validate email formats reliably.

Formula Genius can generate a draft from a plain-English prompt. Supported formulas can be checked with sample cases; review the coverage on the result.

The formula

Prompt

"Validate that a string is a properly formatted email address"

Regex
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

This regex pattern checks if a string conforms to standard email address formatting rules.

Step-by-step breakdown

  1. ^[a-zA-Z0-9._%+-]+: Matches the beginning of the email, allowing letters, numbers, and specific symbols.
  2. @: Requires the presence of the '@' symbol separating the local part from the domain.
  3. [a-zA-Z0-9.-]+: Matches the domain name which can include letters, numbers, dots, and hyphens.
  4. \.: Ensures there is a dot before the domain extension.
  5. [a-zA-Z]{2,}$: Validates that the domain extension is at least two letters long.

Edge cases & warnings

  • Email addresses with multiple '@' symbols are invalid.
  • Email addresses without a domain (e.g., 'user@') are invalid.
  • Email addresses with invalid characters (e.g., 'user@domain!.com') are invalid.

Examples

Prompt

"test@example.com"

Regex
Valid
Prompt

"invalid-email@.com"

Regex
Invalid

Frequently asked questions

What characters are allowed in an email address?

Email addresses can include letters, numbers, dots, and specific symbols like '_', '%', '+', and '-'.

Can I use this regex for all email formats?

This regex covers most common formats but may not capture every edge case of email specifications.

What if the email domain is not a standard TLD?

The regex checks for a minimum of two characters in the domain extension, so it may not validate non-standard TLDs.

Can't find what you need?

Describe a formula in plain English. Formula Genius drafts and explains it, and can check supported formulas on sample cases.