Regex for letters only (alphabets A-Z)

This pattern accepts a value only if it contains English letters and nothing else: no digits, spaces or punctuation. It suits simple name or code fields.

The pattern

/^[A-Za-z]+$/gm

The tester opens with this pattern and the examples below already loaded. Nothing you type is uploaded.

How it works

^
Start of the line or value.
[A-Za-z]+
One or more letters, uppercase or lowercase.
$
End of the line or value.

Examples

Matches

  • Hello
  • regex
  • ABC

Does not match

  • Hello World
  • abc123
  • foo_bar
  • x-y

Use it in JavaScript

const re = /^[A-Za-z]+$/gm;

// Find every match in a block of text
const found = text.match(re);

// Validate that a whole value matches (no stray characters around it)
const exact = new RegExp('^(?:' + re.source + ')$', re.flags.replace('g', ''));
const isValid = exact.test(value);

Limits and tips

  • Real names often contain spaces, hyphens, apostrophes and accented letters, so rejecting them can lock people out. For names use ^\p{L}[\p{L} '-]*$ with the u flag instead.
  • To allow spaces between words use ^[A-Za-z]+(?: [A-Za-z]+)*$, which also rejects leading, trailing and double spaces.
  • For case-insensitive matching add the i flag and shorten the class to [a-z].

Frequently asked questions

How do I allow letters and spaces only?

Use ^[A-Za-z ]+$ for a simple version, or ^[A-Za-z]+(?: [A-Za-z]+)*$ to forbid leading, trailing and repeated spaces.

How do I match letters from any language?

Use the Unicode property escape \p{L} with the u flag, for example ^\p{L}+$.