imo validator

Validate an IMO (International Maritime Organization)

Options

Using with form field
The HTML attributes are used to set the validator options via the Declarative plugin
NameHTML attributeTypeDescription
messagedata-fv-imo___messageStringThe error message
Using the ES6 module
// You might need to change the importing path
import { imo } from '/vendors/@form-validation/cjs/validator-imo';
const result = imo().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-imo
  • Use the imo validator:
import { imo } from '@form-validation/validator-imo';
const result = creditCard().validate({
value: ...,
options: {
message: ...,
},
});

Basic example

imo validator

NPM package example

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

Changelog

v2.0.0
  • Add the npm package