imei validator

Validate an IMEI (International Mobile Station Equipment Identity)

Options

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

Basic example

imei validator

NPM package example

The following snippet shows how to use the imei validator with the npm package:
import { imei } from '@form-validation/validator-imei';
const res1 = imei().validate({
value: '35-209900-176148-1',
options: {
message: 'The value is not valid IMEI',
},
});
// res1.valid === true
const res2 = imei().validate({
value: '490154203237517',
options: {
message: 'The value is not valid IMEI',
},
});
// res2.valid === false

See also

Changelog

v2.0.0
  • Add the npm package