Validators

The richest validators in the class

FormValidation comes with various built-in validators listed in the alphabetical order, split into two groups as following:

Popular validators

In most cases, this list covers validators you often need. All these validators are included in the dist/js/FormValidation(.min).js file.

Name Description
between Check if the input value is between (strictly or not) two given numbers
callback Check if the input value passes a callback method
choice Check if the number of checked boxes are less or more than a given number
creditCard Validate a credit card number
date Validate date
different Check if the input value is different with given value
digits Check if the value contains only digits
emailAddress Validate an email address
file Validate a file
greaterThan Check if the value is greater than or equals to given number
identical Check if the value is the same as one of given value
integer Validate an integer number. Accept both positive and negative number
ip Validate an IP address. Support both IPv4 and IPv6
lessThan Check if the value is less than or equals to given number
notEmpty Check if the value an is empty string
numeric Check if the value is numeric
promise Use Promise to validate value
regexp Check if the value matches given JavaScript regular expression
remote Perform remote checking via Ajax request
stringCase Check if a string is a lower or upper case one
stringLength Validate the length of a string
uri Validate an URL address

Special validators

The following list includes special validators which you often don't need most of the times. In order to use them, you have to include the dist/js/FormValidation.full(.min).js file to your page.

Name Description
base64 Validate a base64 encoded string
bic Validate a BIC (Business Identifier Codes)
color Validate a color in different formats
cusip Validate a CUSIP
ean Validate an EAN (International Article Number)
ein Validate an EIN (Employer Identification Number)
grid Validate a GRId (Global Release Identifier)
hex Validate a hexadecimal number
iban Validate an International Bank Account Number (IBAN)
id Validate an identification number
imei Validate an IMEI (International Mobile Station Equipment Identity)
imo Validate an IMO (International Maritime Organization)
isbn Validate an ISBN (International Standard Book Number). Support both ISBN 10 and ISBN 13
isin Validate an ISIN (International Securities Identification Number)
ismn Validate an ISMN (International Standard Music Number)
issn Validate an ISSN (International Standard Serial Number)
mac Validate a MAC address
meid Validate a MEID (mobile equipment identifier)
phone Validate a phone number
rtn Validate a RTN (Routing transit number)
sedol Validate a SEDOL (Stock Exchange Daily Official List)
siren Validate a Siren number
siret Validate a Siret number
step Check if the value is valid step one
uuid Validate an UUID, support v3, v4, v5
vat Validate VAT number
vin Validate an US VIN (Vehicle Identification Number)
zipCode Validate a zip code

Tip

Look at the custom validator page to see how you can create and reuse your own validator

Using validator globally

You can use any validator globally under the namespace FormValidation.validators in browser if the page includes the FormValidation.min.js or FormValidation.full.min.js script.

The following sample code demonstrates how to use the creditCard validator to validate a credit card number:





document.addEventListener('DOMContentLoaded', function(e) {
    // Now you can access the creditCard validator from 
    const result = FormValidation.validators.creditCard().validate({
        value: '340653705597107',
        options: {
            message: 'The credit card number is not valid',
        },
    });

    // result.valid === true
    // result.meta.type === 'AMERICAN_EXPRESS'
});

Using validator in JavaScript module

All validators are able to be imported and used with JavaScript module. It's super useful if you want to use validator with front-end frameworks (such as React, VueJS, Svelte, .etc), or in server environment with NodeJS frameworks (such as Express).

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


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

const result = creditCard().validate({
    value: '340653705597107',
    options: {
        message: 'The credit card number is not valid',
    },
});
// result.valid === true
// result.meta.type === 'AMERICAN_EXPRESS'