Regex for Email Validation in JavaScript
Production-ready, battle-tested regular expression pattern to validate RFC 5322 email formats in JavaScript/TypeScript.
Staff DevOps & Infrastructure Architect
Verified Command (Single-Click Copy)
Updated: 2026-10-30const isValidEmail = (email) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);📋 Prerequisites
Safe to Run- ✓JavaScript ES6+
💡 Primary Use Cases
Instant visual feedback before network form submission.
# How It Works
Prevents whitespace, requires exactly one @ symbol, ensures non-empty local and domain names, and requires at least one dot in the domain.
Expected Terminal Output
isValidEmail("dev@company.com") // true
isValidEmail("bad-email@") // false
isValidEmail("user@domain..com") // falseGotcha & Common Pitfall
Overly complex 200-character regex strings often cause ReDoS (Regular Expression Denial of Service) vulnerabilities and reject valid emails with plus addressing (e.g. user+tag@domain.com).
Performance & Complexity
ℹ️ Where N is string length. Regex linear-time scan.
Environment & Version Support
High-Performance Edge Hosting
Deploy fullstack Next.js, Astro, and Node apps globally with zero config and automated CI/CD.
# Alternative Methods & Variations
HTML5 Standard Pattern
Standard regex recommended by WHATWG for type="email".
const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;🔍 People Also Ask (Related Quick Answers)
new URL(urlString)/^\d+$/.test(str)Frequently Asked Questions about Regex for Email Validation in JavaScript
Why not use standard RFC 5322 regex?▼
Full RFC 5322 regex is over 6,000 characters long and vulnerable to catastrophic backtracking (ReDoS).
Should email validation be done on client or server?▼
Always validate on both. Client-side regex provides instant UI feedback, but server-side validation + confirmation email is required for security.