Form Validation Plugin jQuery Validity - Free Download HTML5 Validity Based Form Validation Plugin - jQuery validity.js

Free Download HTML5 Validity Based Form Validation Plugin – jQuery validity.js

Posted on

This time I will share jQuery Plugin and tutorial about HTML5 Validity Based Form Validation Plugin – jQuery validity.js, hope it will help you in programming stack.

Form Validation Plugin jQuery Validity - Free Download HTML5 Validity Based Form Validation Plugin - jQuery validity.js
File Size: 8.63 KB
Views Total: 5768
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

validity.js is a small jQuery HTML5 form validation plugin used to validate the values of any form fields using the HTML validity property. You can apply custom styles to the form fields and customizie the error messages when the values are invalid.

How to use it:

1. Download and load the JavaScript file jquery.validity.js after the latest jQuery library.

1 <script src="/path/to/cdn/jquery.min.js"></script>
2 <script src="/path/to/js/jquery.validity.js"></script>

2. Initialize the plugin on the existing html form and done.

1 <form class="validity" method="post" action="/">
2   <!-- Form Fields Here -->
3   <button type="submit">Submit</button>
4 </form>
01 $(function() {
02   $('.validity').validity()
03     .on('submit', function(e) {
04       var $this = $(this),
05           $btn = $this.find('[type="submit"]');
06           $btn.button('loading');
07       if (!$this.valid()) {
08           e.preventDefault();
09           $btn.button('reset');
10       }
11   });
12 });

3. Apply custom styles to the form fields when the form values are valid/invalid.

01 .your-field.error {
02   border-color: red;
03 }
04  
05 .your-field.mismatch {
06   border-color: orange;
07 }
08  
09 .your-field.valid {
10   border-color: green;
11 }

4. Customize the error messages when the form fields are invalid.

1 <input id="name" name="name" class="your-field" type="text" required
2        data-missing="This field is required"
3 >
4  
5 <input id="phone" name="phone" class="your-field" pattern="d{3}[-]d{3}[-]d{4}" type="tel" required
6         data-mismatch="Please match the requested format: 999-999-9999"
7 >
1 //  or
2 $('.validity').validity({
3   messages: {
4     missing: 'Required Filed',
5     mismatch: 'The value entered is invalid'
6   }
7 })

5. Determine the form field to include & exclude.

1 $('.validity').validity({
2   selector: ':input',
3   ignore: ':hidden'
4 })

Changelog:

2020-03-20

  • JS update

2020-01-08

  • JS update

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