Global Source - JavaScript Form Validator
Installation
composer require shankar-thiyagaraajan/javascript-form-validator
Why javascriptFormValidator ?
- It's developed by Core JavaScript.
- It supports most of browsers.
- Light Weight Library
- Very Simple Implementation.
- PowerFull Form Management.
Steps to Integrate to Form :
<script src="./../src/js/formValidator.js"></script>
Then Integrate your form with Validator.
<script>
/.../
var data = {
form: 'new_ticket_form', // Required.
warning_color: 'aa0000', // Optional.
new_class: 'test' // Optional.
};
// Validation Will Init Here.
validate(data);
/.../
</script>
Currently the validation will trigger on submit button trigger.
It has automated listener to eliminating unnecessary changes on form.
Note:
-
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 [but it supports]
-
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//////////////////////////////////////////// //For Simple Required <select class="" required> <option value="-"></option> // Value '-' is used to represent empty. <option value="...">...</option> <option value="...">...</option> <option value="...">...</option> </select> ////////////////////For Textarea Validation////////////////////////////////////////// // For Simple Required <textarea required>.....</textarea>
-
Every Input Fields should have a Label with FOR attributes.
<label for="uname">Name :</label> <input type="text" name="uname" required>
-
Form Tag Should use "novalidate" to Avoid Browser level validation.
<form method="POST/GET.." action="PATH TO HANDLE" ... novalidate> ... ... </form>
This will support to avoid interrupts from browsers.
ex. Chrome Browser
It Will listen the Submit button event Automatically.
So No Need to use <input type="submit"..... onClick="validate()" .....>
Adjust your CSS with the following,
input {
display: block !important;
}
span {
display: inline !important;
}
label {
display: inline !important;
}
License
MIT License