Strict Email Validation Regex Pattern
Comprehensive email validation regex that follows RFC 5322 standards with strict validation rules
javascript
advanced
99.8% accurate
#email
#validation
#forms
#user-input
Pattern Views
45,892
↗ 12.5%Last 30 days
Community Rating
⭐
99.8%
1247 likes
Regular Expression
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
Explanation
This regex pattern provides strict email validation following RFC 5322 standards. It validates the local part (before @) and domain part (after @) with comprehensive character set support and length restrictions.
Code Examples
javascript.example
javascript
// JavaScript implementation
const emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
function isValidEmail(email) {
if (!email || typeof email !== 'string') return false;
if (email.length > 254) return false; // RFC limit
return emailRegex.test(email);
}
// Usage examples
console.log(isValidEmail('user@example.com')); // true
console.log(isValidEmail('invalid.email')); // falsepython.example
python
# Python implementation
import re
EMAIL_REGEX = re.compile(
r'^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$'
)
def is_valid_email(email):
if not email or not isinstance(email, str):
return False
if len(email) > 254: # RFC limit
return False
return bool(EMAIL_REGEX.match(email))
# Usage examples
print(is_valid_email('user@example.com')) # True
print(is_valid_email('invalid.email')) # Falsephp.example
php
<?php
// PHP implementation
function isValidEmail($email) {
if (!is_string($email) || strlen($email) > 254) {
return false;
}
$pattern = '/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/';
return preg_match($pattern, $email) === 1;
}
// Usage examples
var_dump(isValidEmail('user@example.com')); // bool(true)
var_dump(isValidEmail('invalid.email')); // bool(false)
?>Test Cases
✓ Should Match
user@example.com
test.email+tag@domain.co.uk
user.name@subdomain.example.org
firstname-lastname@example-domain.com
user123@test-site.io
✗ Should NOT Match
invalid.email
@example.com
user@
user..name@example.com
user@.example.com
Performance
Speed
fast
Memory
low
Related Patterns
Email Validation Basic
Simpler alternative for basic validation needs
Domain Validation
Validates the domain part specifically
Url Validation
Similar validation logic for URLs