Regex for alphanumeric

Use /^[A-Za-z0-9]+$/ to check that a whole string is for alphanumeric. Every example below is tested against the pattern, and you can open it in the Regex Tester with the samples preloaded.

Updated

/^[A-Za-z0-9]+$/
Open in Regex Tester
InputResult
abc123✓ Match
ABC✓ Match
2026✓ Match
abc 123✗ No match
abc_123✗ No match
abc-123✗ No match
(empty)✗ No match

How the pattern works

PartMeaning
^[A-Za-z0-9]+$One or more ASCII letters or digits, and nothing else — no spaces, underscores or symbols

Code examples

JavaScript

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

Python

import re

bool(re.fullmatch(r'[A-Za-z0-9]+', value))

PHP

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

Notes and limitations

Add _ or - inside the brackets to allow them; \w is a shortcut for [A-Za-z0-9_].

Regex TesterType a pattern and watch matches highlight live in your test text.
Open the tool

Frequently asked questions

What is the regex for alphanumeric?
/^[A-Za-z0-9]+$/ — it matches the whole string. See the table above for what each part does.
Which examples match?
Of the examples tested, these match: abc123, ABC, 2026. The others don’t.
How do I test this regex?
Click “Open in Regex Tester” — the pattern, flags and sample text load automatically, and matches highlight as you edit.