isbn validator

Validate an ISBN (International Standard Book Number)
The validator support both ISBN 10 and ISBN 13.

Options

Using with form field
The HTML attributes are used to set the validator options via the Declarative plugin
NameHTML attributeTypeDescription
messagedata-fv-isbn___messageStringThe error message
Using the ES6 module
// You might need to change the importing path
import { isbn } from '/vendors/@form-validation/cjs/validator-isbn';
const result = isbn().validate({
value: ...,
options: {
message: ...,
},
});
/*
result is an object of
{
valid: true or false,
message: The error message,
meta: {
// Can be null (in case the value is not a valid ISBN) or ISBN10, ISBN13
type: ...
}
}
*/
Using the npm package
  • Install the validator package:
$ npm install @form-validation/validator-isbn
  • Use the isbn validator:
import { isbn } from '@form-validation/validator-isbn';
const result = isbn().validate({
value: ...,
options: {
message: ...,
},
});

Basic example

isbn validator

NPM package example

The following snippet shows how to use the isbn validator with the npm package:
import { isbn } from '@form-validation/validator-isbn';
const res1 = isbn().validate({
value: '9971502100',
options: {
message: 'The value is not valid ISBN',
},
});
// res1.valid === true
// res1.meta.type === 'ISBN10'
const res2 = isbn().validate({
value: '99921-58-10-6',
options: {
message: 'The value is not valid ISBN',
},
});
// res2.valid === false
// res2.meta.type === null

See also

Changelog

v2.0.0
  • Add the npm package