A practical regex check

function isValidEmail(email) {
  return /^[^s@]+@[^s@]+.[^s@]+$/.test(email);
}

console.log(isValidEmail("ada@example.com"));  // true
console.log(isValidEmail("not-an-email"));     // false

The pattern means: one or more non-space, non-@ characters, then @, then a domain, a dot, and an extension.

Let the browser do it

<input type="email" required>

An <input type="email"> field validates the format for free on submit, which is the easiest option for forms.

Check the built-in validity in script

const input = document.querySelector("input[type=email]");
console.log(input.validity.valid);  // true or false

The validity object lets you read the browser’s own verdict without writing any regex at all.

Which approach should you use?

  • type="email" — the easiest and most reliable for HTML forms.
  • A simple regex — when you need to validate a string in code.
  • Common mistake: using a giant, over-strict regex that rejects valid addresses.

Frequently asked questions

Can a regex guarantee an email is real?

No. A regex only checks the format. The only way to confirm an address truly exists is to send a confirmation email and have the user click a link.

Why keep the regex simple?

The full email specification is extremely complex, and strict patterns often reject perfectly valid addresses. A simple check plus a confirmation email is the practical approach.

Want to sharpen your regex and DOM skills? Start with our free JavaScript course.