Back to Home

ISBN-13 Validation Regex

CronOS Team
regexisbnvalidationtutorialbook

Need to generate a regex pattern?

Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!

Generate Regex Pattern

ISBN-13 Validation Regex

Validate ISBN-13 book identification numbers starting with 978 or 979 with optional formatting using regex pattern.

Pattern Breakdown

regex
^(?:ISBN(?:-13)?:? )?(?=[0-9]{13}$|(?=(?:[0-9]+[- ]){4})[- 0-9]{17}$)97[89][- ]?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9]$

Components

ComponentDescriptionMatches
^Start anchorEnsures match from string start
(?:ISBN(?:-13)?:? )?Optional prefixOptional "ISBN" or "ISBN-13" prefix
(?=[0-9]{13}$|...)LookaheadValidates total length
97[89]EAN prefixMust start with 978 or 979
[- ]?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9]ISBN structureGroups separated by hyphens/spaces
$End anchorEnsures match to string end

Examples

Valid:

  • 978-0-306-40615-7
  • 9780306406157
  • ISBN 978-0-306-40615-7
  • 979-0-306-40615-7

Invalid:

  • 977-0-306-40615-7 (wrong prefix)
  • 978-0-306-40615 (missing check digit)
  • 978-0-306-40615-78 (too many digits)

Implementation

JavaScript

javascript
const isbn13Regex = /^(?:ISBN(?:-13)?:? )?(?=[0-9]{13}$|(?=(?:[0-9]+[- ]){4})[- 0-9]{17}$)97[89][- ]?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9]$/;
isbn13Regex.test('978-0-306-40615-7'); // true
isbn13Regex.test('9780306406157'); // true
isbn13Regex.test('979-0-306-40615-7'); // true

Python

python
import re
isbn13_regex = r'^(?:ISBN(?:-13)?:? )?(?=[0-9]{13}$|(?=(?:[0-9]+[- ]){4})[- 0-9]{17}$)97[89][- ]?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9]$'
bool(re.match(isbn13_regex, '978-0-306-40615-7'))  # True

Go

go
isbn13Regex := regexp.MustCompile(`^(?:ISBN(?:-13)?:? )?(?=[0-9]{13}$|(?=(?:[0-9]+[- ]){4})[- 0-9]{17}$)97[89][- ]?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9]$`)
isbn13Regex.MatchString("978-0-306-40615-7") // true

Limitations

  1. No checksum validation: Doesn't validate check digit algorithm
  2. Complex pattern: Hard to read and maintain
  3. Format only: Validates format, not actual ISBN validity

When to Use

  • ISBN-13 format validation
  • Book catalog systems
  • Library management
  • When you need ISBN format checking

For production, consider:

  • Implementing checksum validation
  • Using ISBN parsing libraries
  • Supporting both ISBN-10 and ISBN-13
  • Normalizing to standard format

Need to generate a regex pattern?

Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!

Generate Regex Pattern