Regex to Match ISBN-13 Numbers

Validate ISBN-13 numbers starting with 978 or 979 prefix. Matches 13-digit book identifiers with optional hyphens or spaces as separators. Free regex tester.

Regular Expression

/^(?:97[89][- ]?)?(?:\d[- ]?){9}\d$/

Token Breakdown

TokenDescription
^Anchors at the start of the string (or line in multiline mode)
(?:Start of non-capturing group
9Matches the literal character '9'
7Matches the literal character '7'
[89]Character class — matches any one of: 89
[- ]Character class — matches any one of: -
?Makes the preceding element optional (zero or one times)
)End of group
?Makes the preceding element optional (zero or one times)
(?:Start of non-capturing group
\dMatches 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
\dMatches any digit (0-9)
$Anchors at the end of the string (or line in multiline mode)

Detailed Explanation

This regex validates ISBN-13 (International Standard Book Number) strings. Here is the token-by-token breakdown:

^ — Anchors the match at the start of the string.

(?:97[89][- ]?)? — An optional non-capturing group matching the ISBN-13 prefix. All ISBN-13 numbers begin with either 978 or 979, known as the bookland prefix. 97 matches the fixed first two digits, [89] matches either 8 or 9 for the third digit, and [- ]? optionally matches a separator after the prefix.

(?:\d[- ]?){9} — A non-capturing group matching nine digits with optional separators. Each digit can be followed by an optional hyphen or space. This covers the registration group, registrant, publication, and most of the check digit area.

\d — Matches the final digit, the check digit, without a trailing separator.

$ — Anchors the match at the end of the string.

No flags are used since this validates a single ISBN string.

ISBN-13 became the international standard for book identification in January 2007, replacing ISBN-10. It is a subset of the EAN-13 barcode format, which is why all ISBN-13 numbers start with the bookland prefix 978 or 979. The check digit is calculated using a modulus-10 algorithm, alternating weights of 1 and 3.

Examples include: 9780306406157, 978-0-306-40615-7, and 979-10-90636-07-1. This pattern validates the format but not the check digit arithmetic. It is useful for library catalogs, e-commerce platforms, publishing workflows, and bibliographic databases.

Example Test Strings

InputExpected
9780306406157Match
978-0-306-40615-7Match
979-10-90636-07-1Match
12345678No Match
9760306406157No Match

Try It — Interactive Tester

//
gimsuy
No matches found.
Pattern: 34 charsFlags: noneMatches: 0

Ctrl+Shift+C to copy regex

Customize this pattern →