Back to Home

ISBN-10 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-10 Validation Regex

Validate ISBN-10 book identification numbers with optional formatting and X check digit using regex pattern.

Pattern Breakdown

regex
^(?:ISBN(?:-10)?:? )?(?=[0-9X]{10}$|(?=(?:[0-9]+[- ]){3})[- 0-9X]{13}$)[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X]$

Components

ComponentDescriptionMatches
^Start anchorEnsures match from string start
(?:ISBN(?:-10)?:? )?Optional prefixOptional "ISBN" or "ISBN-10" prefix
(?=[0-9X]{10}$|...)LookaheadValidates total length and format
[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X]ISBN structureGroups separated by hyphens/spaces
[0-9X]Check digitFinal digit or X
$End anchorEnsures match to string end

Examples

Valid:

  • 0-306-40615-2
  • 0306406152
  • ISBN 0-306-40615-2
  • ISBN-10: 0-306-40615-2
  • 0-306-40615-X

Invalid:

  • 0-306-40615 (missing check digit)
  • 0-306-40615-23 (too many digits)
  • ISBN-13: 0-306-40615-2 (wrong prefix)

Implementation

JavaScript

javascript
const isbn10Regex = /^(?:ISBN(?:-10)?:? )?(?=[0-9X]{10}$|(?=(?:[0-9]+[- ]){3})[- 0-9X]{13}$)[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X]$/;
isbn10Regex.test('0-306-40615-2'); // true
isbn10Regex.test('0306406152'); // true
isbn10Regex.test('ISBN 0-306-40615-2'); // true

Python

python
import re
isbn10_regex = r'^(?:ISBN(?:-10)?:? )?(?=[0-9X]{10}$|(?=(?:[0-9]+[- ]){3})[- 0-9X]{13}$)[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X]$'
bool(re.match(isbn10_regex, '0-306-40615-2'))  # True

Go

go
isbn10Regex := regexp.MustCompile(`^(?:ISBN(?:-10)?:? )?(?=[0-9X]{10}$|(?=(?:[0-9]+[- ]){3})[- 0-9X]{13}$)[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X]$`)
isbn10Regex.MatchString("0-306-40615-2") // 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-10 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