Skip to content

Native Javascript (Include ES6) Library to enable HTML-5(type) validation on various browsers.

License

Notifications You must be signed in to change notification settings

global-source/javascript_form_validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Global Source - JavaScript Form Validator

Packagist Packagist Packagist License

Installation

composer require shankar-thiyagaraajan/javascript-form-validator

What's New in this Validator ?

  • Support Native and ES6 Javascript,
  • Pure Javascript Code (No Dependency),
  • Simplified Implementations,
  • HTML 5 validation for all Browsers,
  • Reliable and Dynamic level DOM Validations.

Steps to Integrate to Form :

 <script src="./../src/js/validatorNew.js"></script>
 or
 <script src="./../src/js/validatorNew.es6.js"></script>

Then Integrate your form with Validator.

 // For Native-Javascript
 var myform = jsValidator.init({
        form: 'form2submit',
        forceFilter: true
    });
    
 // For ES6
 var myform = new jsValidator().init({
        form: 'form2submit',
        forceFilter: true
    });
    

Validator Action

Check Form is Valid or Not.

// Retrun status as True|False.
 myform.check() 

Update all Newly created elements to Validator's List.

 // It will update the DOM.
 myform.update() 

Currently the validation will trigger on submit button trigger.

It has automated listener to eliminating unnecessary changes on form.

Note:

  1. Validation take place between tags, so need to specify the ID
    of the Form or any other tags.
   <form id="newUser"> </form>  // Preferred
           
   <div id=newUser> </div>      // Not-Preferred.
  1. Input Fields should specify the type of validation.

    For General Input Validation

    // For Simple Require.
    <input type="text" required name="name">
            
    // For Min Restriction.
    <input type="text" required min=2 name="name">
            
    // For Max Restriction.
    <input type="text" required max=16 name="name">
            
    // For E-Mail Validation.
    <input type="email" required name="name">           
            
    // For Password Match Validation.
    <input type="password" required match="field_name" name="password">

    For Select Validation

  <select class="" required>
    <option value=""></option>    
    <option value="...">...</option>
    <option value="...">...</option>
    <option value="...">...</option>
  </select>

For Textarea Validation

<textarea required>.....</textarea>
  1. Every Input Fields should have a Label with FOR attributes.

          <label for="uname">Name :</label>
          <input type="text" name="uname" required>
  2. In form use "novalidate" to avoid browser interuptions.

         <form method="POST/GET.." action="PATH TO HANDLE" ... novalidate> 
         ...
         ...
         </form>

It Will listen the Submit button event Automatically.

So No Need to use <input type="submit"..... onClick="validate()" .....>

License

MIT License