Validation
Email Local Part (Before @)
Validate just the local part of an email address (the bit before the @).
Try it in RegexPro →Available in
JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("^[a-zA-Z0-9._%+\\-]{1,64}$", "");
const input = "john.doe";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
pyPython
import re
pattern = re.compile(r"^[a-zA-Z0-9._%+\-]{1,64}$")
input_text = "john.doe"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^[a-zA-Z0-9._%+\-]{1,64}$`)
input := `john.doe`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
regexengine-agnostic
^[a-zA-Z0-9._%+\-]{1,64}$Raw source: ^[a-zA-Z0-9._%+\-]{1,64}$
How it works
^ and $ anchor to the full string. [a-zA-Z0-9._%+\-] is the conservative local-part character set (dots, underscores, percent, plus, hyphen for sub-addressing). {1,64} enforces the RFC max length for the local part.
Examples
Input
john.doeMatches
john.doe
Input
user+tagMatches
user+tag
Input
has spaceNo match
—Common use cases
- •Validating partial email input as the user types
- •Splitting and re-assembling email addresses
- •Sub-address (plus-tag) handling in mail systems
- •Form-by-form local-part-only collection
Related patterns
Email Domain Part (After @)
ValidationValidate just the domain portion of an email address — the bit after the @.
Email Address Validation
ValidationMatch and validate email addresses in the standard user@domain.tld format.
BCP 47 Language Tag
ValidationValidate BCP 47 language tags like `en`, `en-US`, `zh-Hant-TW`, or `pt-BR`.
Cron Expression
ValidationValidate standard 5-field Unix cron expressions: minute, hour, day-of-month, month, day-of-week.