Start free · Free tools · Fair usage limits
Browse Tools

Categories

Custom AI Solutions – AI2Flows
LIVE NEWS
Loading latest AI & SEO news…
Home›Tools›Regex Tester›Regex for letters only
Regex pattern · validation

Regex for letters only

Regex for letters only: a tested pattern with examples, a plain-English breakdown, and code for JavaScript, Python, PHP, Java and Go.

Quick answer

Use /^[A-Za-z]+$/ as a letters only regex. It matches "Hello" and "abc", and rejects "Hello1" and "Hello World". Do not use this for people’s names: it rejects José, O’Brien, Anne-Marie and names in non-Latin scripts.

Last updated · Maintained by FreeAIToolz · How we test

/^[A-Za-z]+$/
  • Hellomatches
  • abcmatches
  • XYZmatches
  • Hello1no match
  • Hello Worldno match
  • Joséno match
Open in the full Regex Tester (replace, flags, groups) →

How this regex works

PartMeaning
^[A-Za-z]+$one or more ASCII letters

Examples

InputResult
Hello✓ Matches
abc✓ Matches
XYZ✓ Matches
Hello1✗ No match
Hello World✗ No match
José✗ No match
(empty string)✗ No match

Every example above is checked automatically in JavaScript and Python each time the site is built.

Limitations and edge cases

Do not use this for people’s names: it rejects José, O’Brien, Anne-Marie and names in non-Latin scripts.

When to use this pattern

Simple name parts, language codes and alphabetic-only inputs.

Use it in your language

JavaScript

const re = /^[A-Za-z]+$/;
re.test(input); // true or false

Python

import re
pattern = re.compile(r'^[A-Za-z]+$')
bool(pattern.search(value))

PHP

$ok = preg_match('~^[A-Za-z]+$~', $value) === 1;

Java

Pattern pattern = Pattern.compile("^[A-Za-z]+$");
boolean ok = pattern.matcher(value).find();

Go

re := regexp.MustCompile(`^[A-Za-z]+$`)
ok := re.MatchString(value)

More regex patterns

Frequently asked questions

What is the regex for letters only?
/^[A-Za-z]+$/. Do not use this for people’s names: it rejects José, O’Brien, Anne-Marie and names in non-Latin scripts.
Which languages does this pattern work in?
It is tested in JavaScript and Python and uses syntax that also works in PHP (PCRE) and Java. It also works in Go’s RE2 engine.
Why does the pattern start with ^ and end with $?
They anchor the match to the whole string, so "abcHelloxyz" cannot pass just because it contains a valid part. To search for matches inside longer text, remove ^ and $ (use \b where word boundaries help) and add the g flag.