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).

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.doe

Matches

  • john.doe

Input

user+tag

Matches

  • user+tag

Input

has space

No 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