Back to Home

Standard Email Validation Regex (RFC 5322 Basic)

CronOS Team
regexemailvalidationtutorialrfc-5322

Need to generate a regex pattern?

Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!

Generate Regex Pattern

Standard Email Validation Regex (RFC 5322 Basic)

A comprehensive guide to the RFC 5322 basic email regex pattern ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ and how it works.

Pattern Breakdown

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

Components

ComponentDescriptionMatches
^Start anchorEnsures match from string start
[a-zA-Z0-9._%+-]+Local partOne or more: letters, digits, dots, underscores, percent, plus, hyphens
@SeparatorLiteral @ symbol
[a-zA-Z0-9.-]+Domain nameOne or more: letters, digits, dots, hyphens
\.TLD separatorLiteral dot (escaped)
[a-zA-Z]{2,}TLDTwo or more letters
$End anchorEnsures match to string end

Character Classes

  • a-zA-Z - All uppercase and lowercase letters
  • 0-9 - All digits
  • . - Literal dot (in character class, doesn't need escaping)
  • _ - Underscore
  • % - Percent sign
  • + - Plus sign
  • - - Hyphen (must be at end or start of character class to avoid range interpretation)
  • {2,} - Quantifier: two or more occurrences

Examples

Valid:

  • user@example.com
  • john.doe@company.org
  • user+tag@domain.co.uk
  • test_email@sub-domain.net
  • user%name@example.info
  • user_name@example-domain.com

Invalid:

  • user@domain (missing TLD)
  • @domain.com (missing local part)
  • user@.com (missing domain)
  • user name@domain.com (space not allowed)
  • user@domain.c (TLD must be at least 2 characters)
  • user@@domain.com (double @ symbol)

Implementation

JavaScript

javascript
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
emailRegex.test('user@example.com'); // true
emailRegex.test('john.doe+tag@company.org'); // true

Python

python
import re
email_regex = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
bool(re.match(email_regex, 'user@example.com'))  # True
bool(re.match(email_regex, 'john.doe+tag@company.org'))  # True

Go

go
emailRegex := regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)
emailRegex.MatchString("user@example.com") // true
emailRegex.MatchString("john.doe+tag@company.org") // true

Limitations

  1. Multi-part TLDs: Doesn't match .co.uk, .com.au (would need \.[a-zA-Z]{2,}(\.[a-zA-Z]{2,})?$)
  2. No length validation: RFC 5322 limit is 320 characters total
  3. No quoted strings: Doesn't support "user name"@example.com
  4. No IP addresses: Doesn't allow user@[192.168.1.1]
  5. No comments: Doesn't support user(comment)@example.com

When to Use

  • Client-side form validation
  • Basic format checking for most common email formats
  • Quick validation before API calls
  • When you need to support plus signs and percent signs in local part

For production, consider RFC 5322-compliant patterns or validation libraries, and always verify emails via confirmation messages.

Need to generate a regex pattern?

Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!

Generate Regex Pattern