Tutorial · JavaScript & Node.js

Validate email addresses in JavaScript

Email validation in JavaScript in four steps: instant feedback in the browser, a sensible format check, typo hints, and a real mailbox check on the server.

Updated October 9, 2026 · 2 min read

Validating an email address in JavaScript with a regular expression

1. Let the browser do the first check

<input type="email" name="email" required autocomplete="email">

type="email" gives mobile users the right keyboard and blocks obviously broken input before the form is sent. Check input.validity.valid or listen for the invalid event to show your own message.

2. A practical format check

const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;

function looksLikeEmail(value) {
  const email = value.trim();
  return email.length <= 254 && EMAIL.test(email);
}

looksLikeEmail("anna@example.com"); // true
looksLikeEmail("anna@example");     // false

Don’t write a strict home-made regex. Such patterns often reject real customers (o'brien@example.ie, anna+news@example.com) and still accept asdf@asdf.com. Our email syntax checker shows the individual rules if you need them.

3. Catch typos

Most invalid sign-ups are typos in popular domains: gmial.com, hotmial.com, yaho.com. Suggest a correction instead of rejecting:

const DOMAINS = ["gmail.com", "yahoo.com", "hotmail.com", "outlook.com", "icloud.com"];

function suggest(email) {
  const [user, domain] = email.toLowerCase().split("@");
  const close = DOMAINS.find((d) => d !== domain && levenshtein(d, domain) <= 2);
  return close ? `${user}@${close}` : null;
}

(Any small Levenshtein function works; the email validation API also returns a did_you_mean suggestion.)

4. Check that the mailbox exists (Node.js)

Only a check against the recipient’s mail server tells you whether anna@example.com really exists. Do it on your server:

// Node.js 18+ (built-in fetch)
async function validateEmail(email) {
  const url = `https://api.emailvalidation.io/v1/info?email=${encodeURIComponent(email)}`;
  const res = await fetch(url, { headers: { apikey: process.env.EMAILVALIDATION_KEY } });
  if (!res.ok) throw new Error(`Validation failed: ${res.status}`);
  return res.json();
}

const result = await validateEmail("anna@example.com");
if (result.state === "undeliverable") {
  // reject: the address does not exist
} else if (result.disposable) {
  // ask for a permanent address
}

The response contains state (deliverable, undeliverable or unknown), a reason, a score and the flags format_valid, mx_found, smtp_check, catch_all, disposable, role and free.

  1. type="email" plus the regex for instant feedback.
  2. Typo suggestion when the field loses focus.
  3. API check on submit (server side). Block undeliverable and disposable, accept the rest.
  4. If the API is slow or down, accept the address: never block sign-ups because of a validation outage.

Try it without code in the email validator.

Validate email in other languages

Frequently asked questions

What is the best regex to validate an email in JavaScript?

Keep it simple: /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/ catches typing mistakes without rejecting valid but unusual addresses. It still lets some invalid ones through, such as double dots; the email regex guide has a stricter, tested pattern. Fully RFC-compliant regexes are huge and still cannot tell whether the mailbox exists.

Can I check if an email exists from the browser?

Not directly: browsers cannot open SMTP connections. Call your own backend, which calls an email validation API with your secret key. Never put the API key in front-end code.

Email validation API

Validate emails in your app

emailvalidation.io checks syntax, MX records and the mailbox over SMTP, flags disposable, role and free addresses and returns a quality score, in one request.

/v1/info Email validation API Read the documentation

100 free validations every month. No credit card required.

GET https://api.emailvalidation.io/v1/info?email=support@emailvalidation.io

{
  "email": "support@emailvalidation.io",
  "user": "support",
  "tag": "",
  "domain": "emailvalidation.io",
  "format_valid": true,
  "mx_found": true,
  "smtp_check": true,
  "catch_all": null,
  "role": true,
  "disposable": false,
  "free": false,
  "score": 0.64,
  "state": "deliverable",
  "reason": "low_quality",
  "did_you_mean": "",
  "catch_all_resolution": null,
  "bounce_probability": null,
  "status": "valid",
  "sub_status": "role_based",
  "explanation": "The mailbox exists, but it is a role address (such as info@ or support@), usually read by a team rather than one person.",
  "recommended_action": "send_with_caution"
}

Keep reading

Start using our email validation software today!

Get 100 validations per month for free