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 alphanumeric
Regex pattern · validation

Regex for alphanumeric

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

Quick answer

Use /^[A-Za-z0-9]+$/ as an alphanumeric regex. It matches "abc123" and "ABC", and rejects "abc 123" and "abc-123". Accented letters fail.

Last updated · Maintained by FreeAIToolz · How we test

/^[A-Za-z0-9]+$/
  • abc123matches
  • ABCmatches
  • 2026matches
  • abc 123no match
  • abc-123no match
  • caféno match
Open in the full Regex Tester (replace, flags, groups) →

How this regex works

PartMeaning
^[A-Za-z0-9]+$one or more ASCII letters or digits, nothing else

Examples

InputResult
abc123✓ Matches
ABC✓ Matches
2026✓ Matches
abc 123✗ No match
abc-123✗ No match
(empty string)✗ No match
café✗ No match

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

Limitations and edge cases

Accented letters fail. For Unicode letters and digits use ^[\p{L}\p{N}]+$ with the u flag in JavaScript (Python needs the third-party regex module for \p{…}).

When to use this pattern

Codes, coupon fields and identifiers that must not contain spaces or symbols.

Use it in your language

JavaScript

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

Python

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

PHP

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

Java

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

Go

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

More regex patterns

Frequently asked questions

What is the regex for alphanumeric?
/^[A-Za-z0-9]+$/. Accented letters fail. For Unicode letters and digits use ^[\p{L}\p{N}]+$ with the u flag in JavaScript (Python needs the third-party regex module for \p{…}).
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 "abcabc123xyz" 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.