Regex for ISBN — Pattern Explained with Examples
DodaTech
Updated 2026-06-20
2 min read
In this tutorial, you'll learn about Regex for ISBN. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
International Standard Book Numbers (ISBN) uniquely identify books and other publications. This pattern validates both ISBN-10 (10 digits, last may be X) and ISBN-13 (13 digits beginning with 978 or 979) formats with optional hyphen separators.
The Pattern
# ISBN-13
/^(978|979)\d{10}$/
# ISBN-10
/^\d{9}[\dX]$/
Pattern Breakdown
| Part | Meaning |
|---|---|
^ |
Start-of-string anchor |
(978\|979) |
ISBN-13 prefix: must be 978 or 979 (Bookland country code) |
\d{10}$ |
Exactly 10 digits after the prefix |
^ |
Start-of-string anchor (ISBN-10) |
\d{9} |
Exactly 9 digits |
[\dX]$ |
10th character: digit or X (check digit, X represents 10) |
Matches
978-3-16-148410-00-306-40615-2978014103614403064061529791090636071
Does NOT Match
978-0-306-40615(wrong length)12345678997812345678901(too long)978ABCDEFGHIJ0-306-40615-X(hyphen before X is misplaced)
Language Examples
JavaScript
const isbn13Regex = /^(978|979)\d{10}$/;
const isbn10Regex = /^\d{9}[\dX]$/;
console.log(isbn13Regex.test('9780141036144')); // true
console.log(isbn10Regex.test('0306406152')); // true
console.log(isbn13Regex.test('123456789')); // false
Python
import re
isbn13 = r'^(978|979)\d{10}$'
isbn10 = r'^\d{9}[\dX]$'
print(bool(re.match(isbn13, '9780141036144'))) # True
print(bool(re.match(isbn10, '0306406152'))) # True
print(bool(re.match(isbn10, '123456789'))) # False
Common Pitfalls
- Hyphens are optional in ISBNs but their positions carry meaning (group, publisher, title, check digit) — strip hyphens before validation or use a more complex pattern with hyphen validation
- ISBN-10 check digit can be
X(representing 10) — this is valid and must not be rejected - ISBN-13 prefixes are limited to
978and979— other 13-digit numbers starting with different prefixes are not valid ISBNs - Structural validation does not verify the check digit — real ISBN validation requires computing the check digit using the weighted modulo algorithm (mod 11 for ISBN-10, mod 10 for ISBN-13)
- Some older books have only ISBN-10; after 2007 all new ISBNs are issued as ISBN-13 — support both for legacy catalog data
Real-World Use Cases
- Library catalog systems — validate ISBN entries when adding new books to a database
- Bookstore inventory — verify scanned barcodes (which encode ISBN-13) before looking up product details
- Book trading platforms — validate user-entered ISBNs before listing books for sale or trade
FAQ
Related Patterns
Regex for Numbers Regex for UUID
← Previous
Regex for Semantic Version (SemVer) — Pattern Explained with Examples
Next →
Regex for Coordinates (Latitude/Longitude) — Pattern Explained with Examples
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro