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!
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
| Component | Description | Matches |
|---|---|---|
^ | Start anchor | Ensures match from string start |
(?:ISBN(?:-13)?:? )? | Optional prefix | Optional "ISBN" or "ISBN-13" prefix |
(?=[0-9]{13}$|...) | Lookahead | Validates total length |
97[89] | EAN prefix | Must start with 978 or 979 |
[- ]?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9] | ISBN structure | Groups separated by hyphens/spaces |
$ | End anchor | Ensures match to string end |
Examples
Valid:
978-0-306-40615-79780306406157ISBN 978-0-306-40615-7979-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
- 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-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!