Regex to Match ISBN-10 Numbers
Validate ISBN-10 numbers with or without hyphens or spaces. Matches 10-digit book identifiers with optional check digit X at the end. Free regex tester.
Regular Expression
/^(?:\d[- ]?){9}[\dXx]$/
Token Breakdown
| Token | Description |
|---|---|
| ^ | Anchors at the start of the string (or line in multiline mode) |
| (?: | Start of non-capturing group |
| \d | Matches any digit (0-9) |
| [- ] | Character class — matches any one of: - |
| ? | Makes the preceding element optional (zero or one times) |
| ) | End of group |
| {9} | Matches exactly 9 times |
| [\dXx] | Character class — matches any one of: \dXx |
| $ | Anchors at the end of the string (or line in multiline mode) |
Detailed Explanation
This regex validates ISBN-10 (International Standard Book Number) strings with optional formatting. Here is the token-by-token breakdown:
^ — Anchors the match at the start of the string.
(?:\d[- ]?) — A non-capturing group matching a single digit optionally followed by a hyphen or space separator. ISBN-10 numbers can be written with hyphens (0-306-40615-2), spaces (0 306 40615 2), or without separators (0306406152).
{9} — The preceding group repeats exactly 9 times for the first nine digits of the ISBN.
[\dXx] — Matches the tenth character which is the check digit. The check digit can be a regular digit (0-9) or the letter X (representing the value 10). Both uppercase X and lowercase x are accepted.
$ — Anchors the match at the end of the string.
No flags are used since this validates a single ISBN string.
ISBN-10 was the standard book identification format before 2007 when ISBN-13 became the primary standard. The 10-digit format consists of a group identifier, publisher code, title number, and a check digit calculated using a modulus-11 algorithm. When the check digit calculation results in 10, the letter X is used.
Examples include: 0306406152, 0-306-40615-2, and 080442957X. This pattern validates the structural format but does not verify the check digit calculation. For complete validation, the check digit should be computed and compared programmatically. This pattern is useful for library systems, bookstore applications, and publishing tools.
Example Test Strings
| Input | Expected |
|---|---|
| 0306406152 | Match |
| 0-306-40615-2 | Match |
| 080442957X | Match |
| 123456789 | No Match |
| 12345678901 | No Match |
| 0 306 40615 2 | Match |
Try It — Interactive Tester
22 charsFlags: noneMatches: 0Ctrl+Shift+C to copy regex