# Regex for Alphanumeric Strings

> Alphanumeric regex ^[a-zA-Z0-9]+$ — letters and digits only, no spaces or symbols. Variations for spaces and Unicode letters, explained token by token.

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

^[a-zA-Z0-9]+$ accepts strings made only of ASCII letters and digits: no spaces, punctuation, underscores or accented letters. It's a common rule for codes, IDs and simple usernames.

## Token by token

| Token | Meaning |
|---|---|
| `^` | start of string |
| `[a-zA-Z0-9]+` | one or more ASCII letters (either case) or digits |
| `$` | end of string |

## Examples

- ✓ matches: `abc123`
- ✓ matches: `ABC`
- ✓ matches: `2026`
- ✗ does not match: `abc 123`
- ✗ does not match: `abc_123`
- ✗ does not match: `café`
- ✗ does not match: ``

## Variations

- `^[a-zA-Z0-9 ]+$` — also allow spaces
- `^[\p{L}\p{N}]+$` — letters and digits in any language — needs the u flag in JavaScript

## Language notes

- \w is not the same thing: it also matches the underscore, and in Python 3 it matches Unicode letters by default.

## FAQ

### Why not use \w+?

\w includes the underscore (and, in some languages, accented letters), so it's broader than letters and digits. Spell out [a-zA-Z0-9] when that's what you mean.

### How do I require at least one letter and one digit?

Add lookaheads: ^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z0-9]+$.

## Related patterns

- [Regex for Username Validation](https://www.devkult.com/regex/username.md)
- [Regex for Numbers Only (Digits)](https://www.devkult.com/regex/digits-only.md)
- [Regex for URL Slug Validation](https://www.devkult.com/regex/slug.md)

Open the interactive page: https://www.devkult.com/regex/alphanumeric