Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Validator | Description
**isInt(str [, options])** | check if the string is an integer.<br/><br/>`options` is an object which can contain the keys `min` and/or `max` to check the integer is within boundaries (e.g. `{ min: 10, max: 99 }`). `options` can also contain the key `allow_leading_zeroes`, which when set to false will disallow integer values with leading zeroes (e.g. `{ allow_leading_zeroes: false }`). Finally, `options` can contain the keys `gt` and/or `lt` which will enforce integers being greater than or less than, respectively, the value provided (e.g. `{gt: 1, lt: 4}` for a number between 1 and 4).
**isIP(str [, options])** | check if the string is an IP address (version 4 or 6).<br/><br/>`options` is an object that defaults to `{ version: '' }`.<br/><br/>**Options:**<br/>`version`: defines which IP version to compare to. Accepted values: `4`, `6`, `'4'`, `'6'`.
**isIPRange(str [, version])** | check if the string is an IP Range (version 4 or 6).
**isISBN(str [, options])** | check if the string is an [ISBN][ISBN].<br/><br/>`options` is an object that has no default.<br/>**Options:**<br/>`version`: ISBN version to compare to. Accepted values are '10' and '13'. If none provided, both will be tested.
**isISBN(str [, options])** | check if the string is an [ISBN][ISBN]. ISBN-13 values must begin with `978` or `979` and have a valid check digit; EAN-13 values with other prefixes are rejected.<br/><br/>`options` is an object that has no default.<br/>**Options:**<br/>`version`: ISBN version to compare to. Accepted values are '10' and '13'. If none provided, both will be tested.
**isISIN(str)** | check if the string is an [ISIN][ISIN] (stock/security identifier).
**isISO6346(str)** | check if the string is a valid [ISO 6346](https://en.wikipedia.org/wiki/ISO_6346) shipping container identification.
**isISO6391(str)** | check if the string is a valid [ISO 639-1][ISO 639-1] language code.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isISBN.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assertString from './util/assertString';

const possibleIsbn10 = /^(?:[0-9]{9}X|[0-9]{10})$/;
const possibleIsbn13 = /^(?:[0-9]{13})$/;
const possibleIsbn13 = /^97[89][0-9]{10}$/;
const factor = [1, 3];

export default function isISBN(isbn, options) {
Expand Down
18 changes: 18 additions & 0 deletions test/validators/isISBN.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
import test from '../testFunctions';

describe('isISBN', () => {
[undefined, 13, '13', { version: 13 }, { version: '13' }].forEach((options) => {
it(`should require an ISBN-13 prefix with options ${JSON.stringify(options)}`, () => {
test({
validator: 'isISBN',
args: options === undefined ? [] : [options],
valid: [
'9783836221191', '978-3-8362-2119-1', '978 3 8362 2119 1',
'9791090636071', '979-10-90636-07-1', '979 10 90636 07 1',
],
invalid: [
'4006381333931', '400-6381333931', '400 6381333931',
'1234567890128', '0000000000000',
'9783836221190', '9791090636070',
],
});
});
});

it('should validate ISBNs', () => {
test({
validator: 'isISBN',
Expand Down
Loading