DD
DevDash

Regex for Email with Subdomain

Regex Pattern

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

Email address with a subdomain in the domain part

Quick Answer

The regex pattern for email with subdomain is `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`. Email address with a subdomain in the domain part. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
user@mail.example.com✓ Matches
admin@corp.company.co.uk✓ Matches
test@sub.domain.io✓ Matches
user@example.com✗ No match
user@.com✗ No match
noatsign✗ No match

Code Examples

javascript

const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
const isValid = regex.test(value);

python

import re
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/', $value)) {
    echo "valid";
}

java

String pattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.