Skip to content
EngineeringAll explainers

What is alphanumeric: character sets, validation, and encoding

Alphanumeric means letters plus digits and nothing else. See the 62 ASCII characters, Unicode letter and number classes, regex patterns for JavaScript and Python, EBCDIC pitfalls, and where an alphanumeric allow-list helps security.

Published: Updated: Reading time: 6 min
On this page

Alphanumeric data is any string made only of letters (A to Z, uppercase and lowercase) and digits (0 to 9). It excludes spaces, punctuation, mathematical symbols and non-printable control characters.

Some alphanumeric examples: an order number like INV2026A7, a license key, a car plate, a booking reference. Compare that with numeric data (digits only, like 2026) and alphabetic data (letters only, like Idealogic). In custom software development and web development, alphanumeric rules show up in URL slugs, generated identifiers, database keys and form validation. Strings that stay inside this set travel between databases, network protocols and client apps without escaping or getting mangled by a charset mismatch.

Alphanumeric character sets and definitions

In ASCII, formally specified in IETF RFC 20, alphanumeric characters sit in three continuous bands, 62 characters in total.

SetASCII decimal codesCharactersCount
Digits48 to 570 to 910
Uppercase letters65 to 90A to Z26
Lowercase letters97 to 122a to z26
ASCII alphanumeric total62
Unicode alphanumeric\p{L} plus \p{N}letters and numbers in any scriptthousands

Plain 7-bit ASCII breaks down fast once your users aren't all writing English. Under the Unicode Standard, alphanumeric usually means characters in the Letter (\p{L}) and Number (\p{N}) categories. That covers letters with diacritics such as é or ñ, Cyrillic, and digits from other scripts such as Arabic-Indic digits, while punctuation and formatting symbols stay out.

There's one catch. \p{N} isn't only decimal digits. It also includes letter-like numbers (Roman numeral symbols) and other numbers such as superscript two, per the Unicode Character Database. If you really mean 0 to 9 in any script, use \p{Nd}.

Alphanumeric validation patterns in software

Which pattern you pick depends on whether your app has to accept non-Latin text.

In JavaScript, an ASCII-only check is the pattern ^[A-Za-z0-9]+$, and the Unicode version is ^[\p{L}\p{N}]+$ with the u flag. In Python, the ASCII check is re.fullmatch with [A-Za-z0-9]+, while str.isalnum() is the Unicode-aware shortcut.

The ASCII check anchors at both ends, so every character has to fall in one of the three ranges. That's what you want for user IDs, license keys and transaction references: it keeps stray whitespace and invisible zero-width spaces out of your database. In Python, use re.fullmatch instead of ^...$, because Python's $ also matches right before a trailing newline (Python re docs). And watch str.isalnum(): it's Unicode-aware, so it accepts letters and digits far outside ASCII.

For names and addresses, Unicode property escapes let you accept German, Spanish or Ukrainian text without rejecting it as invalid. Engine support varies, though. JavaScript needs the u flag (MDN), and Python's built-in re doesn't support \p at all, so you'd reach for the third-party regex package.

Alphanumeric encoding and representations

Encoding decides how these characters are stored in memory and sent over the wire.

UTF-8 is the dominant encoding on the web, and it was designed so that every ASCII character keeps its original code. Each ASCII letter or digit takes exactly one byte (8 bits). An alphanumeric ID of 12 characters is 12 bytes, nothing more.

Legacy enterprise systems are a different story. IBM mainframes often use EBCDIC (Extended Binary Coded Decimal Interchange Code), where letters aren't contiguous: there are gaps in the byte values between I and J and between R and S (IBM CCSID 037). EBCDIC is also code-page dependent, so the exact byte for a character varies. Code that assumes "A to Z is one range" will sort or validate wrongly here. That's why ASCII to EBCDIC translation in system integration projects needs explicit mapping tables.

Security implications of alphanumeric constraints

An alphanumeric allow-list is useful, but it's a supporting control, not your main defense. OWASP's Input Validation Cheat Sheet treats validation as defense in depth. The primary fixes are specific to each attack:

  • SQL injection: parameterized queries (OWASP SQL Injection Prevention). Rejecting quotes isn't enough, since injection into a numeric context can work without any.
  • Cross-site scripting needs context-aware output encoding (OWASP XSS Prevention).
  • Command injection is best avoided by not passing user input to a shell at all.

Still, an alphanumeric check on usernames, invoice numbers or filter values strips out the quotes, pipes, backticks and angle brackets those attacks usually depend on. It also narrows what a later bug can be exploited with. The same goes for payload fields in an API integration: validate identifiers against a strict pattern before they hit any downstream system.

Paths and URLs are similar. A dot-dot-slash traversal needs . and /, so an alphanumeric-only resource ID blocks it, though canonicalizing paths on the server is the real protection. Alphanumeric-only is actually stricter than URLs require: RFC 3986 also allows -, ., _ and ~ unescaped.

Passwords go the other way. NIST SP 800-63B Revision 4 says verifiers shouldn't impose composition rules (such as "must contain letters and digits") and should accept all printing ASCII characters, the space and Unicode. So don't restrict passwords to alphanumeric characters.

Best practices for database storage and indexing

A few schema decisions matter when you store alphanumeric identifiers.

Pick column types per engine

Fixed-length character columns can suit identifiers that really are fixed length, like order numbers in a set format. Whether they beat variable-length types depends on your database. In PostgreSQL, for example, CHAR(n) has no performance advantage over VARCHAR. For usernames, a variable-length type with a realistic length cap is the usual choice. Note that a standard UUID (36 characters with hyphens, see RFC 9562) isn't strictly alphanumeric, and many databases have a native UUID type that's better than storing the text.

Decide on case sensitivity up front

Depending on collation, comparisons can be case-sensitive or not. For logins and email prefixes, store a normalized lowercase version alongside the original. Unique indexes get simpler, and you avoid two accounts that differ only by capitalization.

Designing identifiers or validation for a system that has to talk to legacy platforms? That work usually sits inside a wider custom software development or integration project.

Frequently asked questions

  • Alphanumeric describes text made only of letters (A to Z, uppercase and lowercase) and digits (0 to 9). Punctuation, spaces, symbols and control characters don't count.

  • No. Alphabetic means letters only, numeric means digits only, and alphanumeric allows both. So ABC is alphabetic, 2026 is numeric, and A7K2 is alphanumeric. Plenty of identifiers you see every day, such as order numbers, license keys and car plates, are alphanumeric for exactly this reason: mixing the two sets packs more combinations into a short string.

  • No. Spaces, underscores, hyphens and symbols such as @, # or $ are all non-alphanumeric. That's why a standard UUID, which contains four hyphens, isn't strictly alphanumeric even though its other characters are hex digits and letters.

  • For ASCII, ^[A-Za-z0-9]+$ matches a string of letters and digits. In Python, prefer re.fullmatch with [A-Za-z0-9]+, because $ in Python also matches just before a trailing newline. For international text in JavaScript, use /^[\p{L}\p{N}]+$/u. The u flag is required, since without it the engine doesn't read \p as a property escape. Python's built-in re module doesn't support \p at all, so you'd need the third-party regex package. Also note that \p{N} covers more than 0 to 9 (it includes characters like Roman numeral symbols), so use \p{Nd} if you mean decimal digits only.

  • Mostly for predictable identifiers: safe URL slugs, file names and keys that pass between systems without escaping. An alphanumeric allow-list also adds a layer of defense against injection, but OWASP treats input validation as a secondary control. Parameterized queries stop SQL injection and output encoding stops XSS.

Still unanswered
Ask us directly

A senior engineer replies under 4 hours.