JavaScript / ECMAScript

Alphanumeric Only in JS

Match strings containing only letters (A–Z, a–z) and digits (0–9), with no spaces or special characters.

Try it in the JS tester →

Pattern

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

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^[a-zA-Z0-9]+$", "");
const input = "Hello123";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

^ and $ anchor to the full string. [a-zA-Z0-9]+ requires one or more characters from the combined letter and digit set. Any space, punctuation, or symbol will cause the match to fail.

Examples

Input

Hello123

Matches

  • Hello123

Input

abc

Matches

  • abc

Input

has space

No match

Same pattern, other engines

← Back to Alphanumeric Only overview (all engines)