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!
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
| Component | Description | Matches |
|---|---|---|
^ | Start anchor | Ensures match from string start |
(?:ISBN(?:-10)?:? )? | Optional prefix | Optional "ISBN" or "ISBN-10" prefix |
(?=[0-9X]{10}$|...) | Lookahead | Validates total length and format |
[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X] | ISBN structure | Groups separated by hyphens/spaces |
[0-9X] | Check digit | Final digit or X |
$ | End anchor | Ensures match to string end |
Examples
Valid:
0-306-40615-20306406152ISBN 0-306-40615-2ISBN-10: 0-306-40615-20-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
- No checksum validation: Doesn't validate check digit algorithm
- Complex pattern: Hard to read and maintain
- 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!