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.
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.
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:
<script src="/vendors/formvalidation/dist/js/FormValidation.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function (e) {
const result = FormValidation.validators.creditCard().validate({
value: '340653705597107',
options: {
message: 'The credit card number is not valid',
},
});
});
</script>
Using validator in ES6 module
All validators are able to be imported and used with ES6 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 ES6 module:
import creditCard from 'formvalidation/dist/es6/validators/creditCard';
const result = creditCard().validate({
value: '340653705597107',
options: {
message: 'The credit card number is not valid',
},
});