splitforms.com

Free tool - runs in your browser

Alphanumeric regex tester

Test letters and numbers only, with optional spaces, underscores and hyphens, Unicode letters or a length limit. Pick a preset, edit the regex and paste strings one per line. Copy JavaScript, Python or an HTML pattern when you are ready.

One or more ASCII letters or digits; does not require both. Spaces and punctuation are excluded.

3 of 6 match

  • Matchabc123
  • MatchABC
  • Match123
  • No matchabc 123
  • No matchuser_name
  • No matchcafé

HTML pattern uses the v flag and matches the entire input. Add required to reject empty values. The Unicode Python snippet requires the third-party regex module; other snippets use re.ASCII. Validate again on the server.

Alphanumeric regex patterns

Choose a format that fits your input. The default pattern ^[A-Za-z0-9]+$ matches ASCII letters and digits only. Each preset is checked against its match and no-match samples.

PresetRegexMatch / no match examplesNotes
ASCII letters and digits only^[A-Za-z0-9]+$Match: abc123, ABC, 123
No match: abc 123, user_name, café; empty string
One or more ASCII letters or digits; does not require both. Spaces and punctuation are excluded.
Alphanumeric with spaces^[A-Za-z0-9 ]+$Match: abc 123, Hello World, abc123 ,
No match: abc_123, abc 123, café; empty string
Allows ordinary spaces, including leading, trailing and all-space values. Trim first and reject an empty result when needed; tabs are excluded.
Alphanumeric plus underscore and hyphen^[A-Za-z0-9_-]+$Match: user_name, my-slug123, abc123
No match: abc 123, user.name, café; empty string
For slugs and handles; allows separators anywhere, including separator-only values. Add position rules if your application needs them.
At least one letter AND one digit^(?=.*[A-Za-z])(?=.*\d)[A-Za-z0-9]+$Match: abc123, a1, 9Z
No match: abcdef, 123456, abc 123; empty string
Two lookaheads require an ASCII letter and a digit; only ASCII alphanumeric characters may appear.
Unicode letters and digits^[\p{L}\p{N}]+$Match: café123, 東京123, مرحبا١٢٣, abc123
No match: café 123, user_name, 😀, é; empty string
JavaScript requires u; HTML pattern uses v. Python: use the regex module for \p properties, or [^\W_]+ with standard re. Combining marks are excluded; consider NFC normalization for decomposed accents.
Fixed length range: 6-12 characters^[A-Za-z0-9]{6,12}$Match: abc123, ABCdef123456, 123456
No match: abc12, ABCdef1234567, abc 123; empty string
Requires 6 through 12 ASCII letters or digits. For exactly 8 characters, replace {6,12} with {8}.

Alphanumeric regex in an HTML form

alphanumeric.html

<label for="code">Letters and numbers only</label>
<input id="code" name="code" type="text" pattern="[A-Za-z0-9]+" required>

A text input can enforce letters and numbers with the pattern attribute; HTML matches the entire value and uses the v flag, which supports Unicode properties. Add required to reject an empty value. The handle preset escapes the literal hyphen for v-mode character classes. Trim spaces before validation if your field requires it. Validate again on the server.

Why [a-zA-Z0-9] and not \w

\w also matches underscore. In Python and some other engines it includes Unicode letters and numbers; JavaScript primarily uses ASCII word characters, with a few extra case-folding matches under iu. Use [a-zA-Z0-9] for an explicit ASCII rule, or Unicode properties with the u flag for international input.

References: HTML pattern rules, JavaScript Unicode properties and Python re documentation.

Alphanumeric regex FAQ

What regex matches alphanumeric characters only?

Use ^[A-Za-z0-9]+$ for one or more ASCII letters or digits. It rejects spaces, underscores, punctuation and empty strings. It does not require both a letter and a digit.

How do I allow spaces in an alphanumeric regex?

Use ^[A-Za-z0-9 ]+$ to allow ordinary spaces alongside ASCII letters and digits. It also accepts leading, trailing and all-space values. Trim first and reject an empty result if those are unwanted. Tabs and line breaks are not allowed.

How do I require at least one letter and one number?

Use ^(?=.*[A-Za-z])(?=.*\d)[A-Za-z0-9]+$. The two lookaheads require a letter and a digit; the final character class rejects spaces and punctuation.

How do I match Unicode letters and digits?

Use /^[\p{L}\p{N}]+$/u in JavaScript. Python needs the third-party regex module for these properties, or use [^\W_]+ with standard re for Unicode alphanumeric characters. HTML pattern uses the v flag. Decomposed accents contain combining marks, so normalize to NFC first when appropriate; standalone marks are excluded.

Should I validate alphanumeric input on the server?

Yes. Browser validation can be bypassed. Apply the same character, length and normalization rules on the server. Add required in HTML if the value must not be empty.

More free form tools

Form backend cost calculator

Enter monthly submissions and compare the cheapest listed plan across eight form backends.

Email deliverability checker

Enter a domain to check its SPF, DMARC and MX records and get a plain-English fix for each.

SPF record checker

Look up a domain's SPF record, see each mechanism explained and count DNS lookups against the 10-lookup limit.

DMARC record generator

Pick a policy and report address and copy a ready _dmarc TXT record.

DMARC checker

Look up a domain's DMARC record and see the policy and every tag explained.

DKIM record checker

Enter a domain and selector to check its DKIM key, with presets for common senders.

SPF record generator

Tick your email providers and copy one SPF TXT record with a lookup count.

Contact form spam checker

Paste form HTML to audit its honeypot, endpoint, CAPTCHA markers and spam resistance.

Honeypot field generator

Generate a hidden anti-spam input with your chosen name and hiding technique.

Form action URL tester

Check a form action URL for reachability, CORS headers, POST acceptance and backend.

Email obfuscator

Encode your email so spam scrapers can't read it but people can still click it.

Mailto link generator

Build a mailto: URL with recipients, CC, BCC, subject and a pre-filled body.

HMAC-SHA256 generator

Generate and verify webhook signatures for common providers in your browser.

URL encoder and decoder

Encode text, build an x-www-form-urlencoded body or parse a query string.

UTM builder

Build campaign URLs with UTM parameters, tag a CSV in bulk and check tagged links.

HTML to JSX converter

Paste HTML and get JSX or a working React/Next.js form component.

Image to Base64 converter

Convert images to Base64 data URLs in your browser and copy HTML and CSS snippets.

Base64 to image converter

Paste a Base64 data URI to preview and download the decoded image.

Base64 decode & encode

Decode Base64 to readable UTF-8 text or encode text to Base64, locally in your browser.

URL to Base64 converter

Fetch a direct image URL in your browser and get its Base64 data URL.

AI form generator

Describe your form in plain English and copy working HTML.

See all free tools