ean validator

Validate an EAN (International Article Number)

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-ean___message String The error message

Using with JavaScript module


// You might need to change the importing path
import ean from 'formvalidation/validators/ean';

const result = ean().validate({
    value: ...,
    options: {
        message: ...,
    },
});
/*
result is an object of
{
    valid: true or false,
    message: The error message     
}
*/

Basic Example

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

Sample Is valid?
73513537
9780471117094
4006381333931
73513536

Module Example

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


// You might need to change the importing path
import ean from 'formvalidation/validators/ean';

const res1 = ean().validate({
    value: '9780471117094',
    options: {
        message: 'The value is not valid EAN',
    },
});
// res1.valid === true

const res2 = ean().validate({
    value: '73513536',
    options: {
        message: 'The value is not valid EAN',
    },
});
// res2.valid === false

Related validators

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

Name Description
isbn Validate an ISBN (International Standard Book Number). Support both ISBN 10 and ISBN 13
issn Validate an ISSN (International Standard Serial Number)