Skip to content
Private: files never leave your device

Regex for Email Validation (That Actually Works)

Every developer eventually needs an email regex, and many copy a 400-character monster. You do not need one. Here are simple patterns that catch real mistakes, why perfection is impossible, and how to test them live.

Email validation with regular expressions: a simple pattern, a stricter one, the browser built-in email input and confirmation emails as the real proof

For most forms, this is enough:

^[^\s@]+@[^\s@]+\.[^\s@]+$

It requires something before the @, something after it, and a dot in the domain, with no spaces. It catches the typos people actually make. Test it with your own examples in the Regex Tester.

Patterns compared

PatternCatchesTrade-off
^[^\s@]+@[^\s@]+\.[^\s@]+$Missing @, missing domain dot, spacesAllows some odd but harmless input
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$Also odd characters and one-letter endingsRejects valid non-English addresses
The full RFC 5322 regexAlmost exactly the standardUnreadable, slow, and still not proof the address works
Why no regex is perfect: the email standard allows quoted names, comments and international characters, while some valid-looking addresses do not exist. Only a confirmation email proves an address works.

Use it in JavaScript

const isEmail = (s) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s.trim());
isEmail("anna@example.com"); // true
isEmail("anna@example");     // false

In HTML forms, <input type="email"> already checks the format in every modern browser and shows a friendly message. Add the regex for server-side checks, where browser validation can be bypassed.

Test patterns live

  1. Open Regex Tester and click the Email sample, or paste your own pattern.
  2. Turn on the m (multiline) and g (global) flags.
  3. Paste test addresses, one per line: good ones, and mistakes like anna@@example.com or anna@example.
  4. Matches are highlighted and listed with their position and groups.
Test your pattern

Live highlighting, groups, flags and a cheat sheet. Private.

Regex Tester

Validation checklist

  • Trim spaces before checking; copy-paste often adds them.
  • Lowercase the domain part before comparing addresses.
  • Do not block plus addressing like anna+news@example.com; it is valid and popular.
  • Confirm by sending a link before trusting an address for anything important.
  • Rate-limit sign-up forms to stop bots, which a regex cannot do.

Cleaning a list of addresses? Remove Duplicate Lines and Find and Replace with regex make quick work of it.

Frequently asked questions

What is the best regex for email validation?

A simple one such as ^[^\s@]+@[^\s@]+\.[^\s@]+$ catches real typos. Confirm the address by email for certainty.

Can a regex fully validate an email address?

No. The standard is too complex, and a valid format does not mean the mailbox exists.

Is input type=email enough?

For the browser, yes, but always validate again on the server, since browser checks can be bypassed.

Should I allow plus signs in emails?

Yes. Addresses like name+tag@example.com are valid and widely used.

How do I test a regex?

Paste the pattern and sample text into Regex Tester. Matches are highlighted as you type.