T
ToolPrime

Regex for Alphanumeric Only

Validates strings containing only letters and numbers.

Pattern

/^[a-zA-Z0-9]+$/

Live Tester

Enter a string to test

Examples

Hello123
abc
456
hello world
test!
a-b

Pattern Breakdown

^[a-zA-Z0-9]+ — alphanumeric from start

$ — to end

Code Snippets

Javascript

/^[a-zA-Z0-9]+$/.test("Hello123"); // true

Python

bool(re.match(r"^[a-zA-Z0-9]+$", "Hello123"))  # True

Php

preg_match('/^[a-zA-Z0-9]+$/', "Hello123"); // 1

Related Patterns

Frequently Asked Questions

What is the regex for Alphanumeric Only?
The regex pattern for Alphanumeric Only is /^[a-zA-Z0-9]+$/. Validates strings containing only letters and numbers.
How do I use the Alphanumeric Only regex in JavaScript?
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the Alphanumeric Only pattern match?
It matches strings like Hello123; it rejects strings like hello world. See the Examples section above for the full list of matching and non-matching cases.

Related Tools