DD
DevDash

Regex for ISBN-13

Regex Pattern

^97[89]\d{10}$

ISBN-13 — starts with 978 or 979, 13 digits total

Quick Answer

The regex pattern for isbn-13 is `^97[89]\d{10}$`. ISBN-13 — starts with 978 or 979, 13 digits total. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
9780306406157✓ Matches
9791234567890✓ Matches
9780131103627✓ Matches
9760306406157✗ No match
978030640615✗ No match
97803064061571✗ No match

Code Examples

javascript

const regex = /^97[89]\d{10}$/;
const isValid = regex.test(value);

python

import re
pattern = r'^97[89]\d{10}$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^97[89]\d{10}$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^97[89]\d{10}$/', $value)) {
    echo "valid";
}

java

String pattern = "^97[89]\\d{10}$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.