isbn validator

Validate an ISBN (International Standard Book Number). 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

Name HTML attribute Type Description
message data-fv-isbn___message String The error message

Using with JavaScript module


// You might need to change the importing path
import isbn from 'formvalidation/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

You can click on sample to see if it's a valid or invalid ISBN.

Sample Is valid?
9971502100
99921-58-10-7
960 425 059 0
99921-58-10-6
9780306406157
978-0-306-40615-7
978 0 306 40615 7
978-0-306-40615-6

Module Example

The following snippet shows how to use the isbn validator with JavaScript module:


// You might need to change the importing path
import isbn from 'formvalidation/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

Related validators

The following validators are similar to this one and might be useful to you.

Name Description
ean Validate an EAN (International Article Number)
issn Validate an ISSN (International Standard Serial Number)