Skip to content
Regex for ISBN — Pattern Explained with Examples

Regex for ISBN — Pattern Explained with Examples

DodaTech Updated Jun 20, 2026 3 min read

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

PartMeaning
^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-0
  • 0-306-40615-2
  • 9780141036144
  • 0306406152
  • 9791090636071

Does NOT Match

  • 978-0-306-40615 (wrong length)
  • 123456789
  • 97812345678901 (too long)
  • 978ABCDEFGHIJ
  • 0-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 978 and 979 — 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

What is the difference between ISBN-10 and ISBN-13?
ISBN-10 uses 10 digits with a modulo-11 check digit (X for value 10). ISBN-13 uses 13 digits starting with 978 or 979, with a modulo-10 check digit. ISBN-13 is compatible with EAN barcodes. After 2007, all new ISBNs are issued as ISBN-13, but ISBN-10 codes remain valid for legacy books.
Does this pattern validate the check digit?
No. Regex can only validate the structural format — correct length, allowed characters, and prefix. Check digit validation requires computing the weighted sum and comparing it to the check digit. For ISBN-10, use modulo 11 weighting; for ISBN-13, use alternating weights of 1 and 3.

Related Patterns

Regex for Numbers Regex for UUID

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro