Robust Modular HTML5 Form Validation Plugin - Form Validator

File Size: 245 KB
Views Total: 4040
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
Robust Modular HTML5 Form Validation Plugin - Form Validator

A robust, flexible, customizable and modular form validator that supports both native HTML5 form validation features and custom validation rules.

Modules supported:

  • date.js: date & time validation
  • file.js: file mime, extension, size and dimension validation
  • html5.js: make this plugin serve as an html5 fallback
  • jsconf.js: configure form validation using javascript
  • location.js: Country, US state, longitude and latitude validation
  • logic.js: depends-on and if-answered validation
  • sanitize.js: add sanitation functions to inputs (uppercase, lowercase, capitalize, trim, trimLeft, trimRight, numberFormat, insertLeft, insertRight, strip, escape (replace <, >, &, ' and " with HTML entities))
  • security.js: Great for registration forms (spamcheck, confirmation, strength, backend, credit card, cvv).
  • toggleDisabled.j: takes care of disabling/enabling submit buttons in forms, depending on if the inputs of the form is valid or not.
  • uk.js: adds validators typically used on websites in the UK (ukvatnumber, ukutr, uknin)
  • brazil.js: adds validators typically used on websites in Brazil (cpf, cep, brphone)
  • poland.js: adds validators typically used on websites in Poland (plpesel)
  • poland.js: adds validators typically used on websites in Sweden (validate_swesec (Social security number), validate_swemobile, validate_validate_municipality, validate_county, validate_swephone)

Install the Form Validator:

npm install jquery-form-validator

# Bower
bower install jquery-form-validator

Basic usage:

1. Include the main JavaScript file and modular files of your choice after JQuery library as this:

<script src="jquery.min.js"></script>
<script src="jquery.form-validator.min.js"></script>
<script src="module-name.min.js"></script>

2. Add validation rules to your form fields using HTML5 data attributes:

<form action="#" method="POST">
    <input data-validation="length alphanumeric" data-validation-length="min4">
    Year (yyyy-mm-dd):
    <input data-validation="date" data-validation-format="yyyy-mm-dd">
    <input data-validation="url">
    <input type="submit">

3. Initialize the form validator:


4. Default plugin customization options.


  // Names of inputs not to be validated
  ignore: [], 

  // Class that will be put on elements which value is invalid
  errorElementClass: 'error', 

  // Class that will be put on elements that has been validated with success
  successElementClass: 'valid', 

  // Border color of elements which value is invalid
  // empty string to not change border color
  borderColorOnError: '#b94a48', 

  // class name of div containing error messages when validation fails
  errorMessageClass: 'form-error', 

  // name of the attribute holding the validation rules
  validationRuleAttribute: 'data-validation', 

  // define custom err msg inline with element
  validationErrorMsgAttribute: 'data-validation-error-msg', 

  // Can be either "top" or "inline"
  errorMessagePosition: 'inline', 

  // template
  errorMessageTemplate: {
    container: '<div class="{errorMessageClass} alert alert-danger">{messages}</div>',
    messages: '<strong>{errorTitle}</strong><ul>{fields}</ul>',
    field: '<li>{msg}</li>'

  // scroll to top if the form wasn't validated
  scrollToTopOnError: true,

  // date format
  dateFormat: 'yyyy-mm-dd',

  // apply class="valid" even if the input wasn't validated
  addValidClassOnAll: false, 

  // custom decimal separator
  decimalSeparator: '.',

  // twitter-bootstrap default class name
  inputParentClassOnError: 'has-error', 

  // twitter-bootstrap default class name
  inputParentClassOnSuccess: 'has-success', 

  // whether or not hidden inputs should be validated
  validateHiddenInputs: false, 

  // callback functions
  inlineErrorMessageCallback: false,
  submitErrorMessageCallback: false



  • v2.3.79


  • v2.3.76


  • Add Arabic language


  • Async validators should be applied to original validator object added when calling .addAsyncValidator


  • make it possible to inline language files


  • v2.3.72


  • Support Turkish Language


  • Added support for age-range in birthday validator


  • v2.3.62


  • v2.3.61


  • [fix] use successElementClass instead of valid class


  • various fixes


  • Add better green check mark

This awesome jQuery plugin is developed by victorjonsson. For more Advanced Usages, please check the demo page or visit the official website.