Client-side Form Input Validation with jQuery and Bootstrap

Client-side Form Input Validation with jQuery and Bootstrap
File Size: 21.2 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A simple lightweight JavaScript library that validates the form inputs and displays the error messages in the Bootstrap modal dialog.

How to use it:

1. Include the required Bootstrap framework on your web page.

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">  <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>

2. The Bootstrap modal component requires jQuery library to be loaded before the Bootstrap.js.

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

3. Include the validation.js

<script src="validation.js"></script>

4. Add Html5 data-* attributes to your form controls as follows.

  • data-title: set the error messages.
  • data-regex: set the password strength using REGEX.
  • data-match: check passwords match.
<input type="text" 
       data-title="Please enter your name"
>

<input type="password" 
       data-title="Password required" 
	   data-regex="^[^\s]{6,20}$" 
	   data-regex-title="Please a enter a password 6 - 20 characters in length"
>

<input type="password" 
       data-title="Confirmation password required" 
	   data-match="password" 
	   data-match-title="Your password and confirmation password do not match"
>

Change log:

2017-04-13

  • Fixed issue where a select element would return a null value and trim would fail

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