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 with ES6 module
// You might need to change the importing path
import isbn from 'formvalidation/dist/es6/validators/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: ...
}
}
*/

Basic example

isbn validator

ES6 Module Example

The following snippet shows how to use the isbn validator with ES6 module:
// You might need to change the importing path
import isbn from 'formvalidation/dist/es6/validators/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