Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

219 Commits

Repository files navigation

Global Source - JavaScript Form Validator [Ready to Use]

PackagistPackagistLicense

Installation

git clone https://github.com/global-source/javascript_form_validator.git
git checkout -b [VERSION]

Why me ?

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

Steps to Integrate to Form :

<scriptsrc="formValidator.js"></script>
or
<scriptsrc="formValidator.es6.js"></script>

Then Integrate your form with Validator.

varmyform=newjsValidator().init({form: 'form2submit',// #id});

Options

NameValuesDescriptionsMandatory
form#IDID of the Form to handle validations and filters.Yes
forceFilterBoolTrue, to allow form filter without form validations. False, default.No
messageObjectResponse message for all HTML elements.No
LogBoolTo enable error log on console.No

Actions

check() : Return as Form is Valid or Not.

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

update() : Update Newly created DOM elements to Validator.

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

Attributes

NameValuesDescriptions
requiredTrue, FalseSet the fields is required to submit the Form.
minIntegerTo set the Minimun value to proceed.
maxIntegerTo set the Maximum value to proceed.
data-maxlength="10"IntegerTo set the Maximum length of characters to proceed.
maxLength="10"IntegerTo set the Maximum length of characters to proceed.
type="password"AlphaNumericTo set and compare password.
type="email"AlphaNumericTo check the email is valid or not.
type="file"string ['png,jpeg..']To check the file format is allowed or not.
data-message="Error Message"StringUser defined, element based direct error message to handle.
data-allow="onlyAlpha"Alphabets OnlyAllow only string, no digits and no special characters.
data-allow="string"Alphabets + Numbers OnlyAllow only string and digits, no special characters.
data-allowSpecial="/_+"Special charactersAllow only given special characters.
[INDEX]NumericNow supports Min&Max validation to show the limit.

Currently the validation will trigger on submit button trigger.

It has automated listener to monitor every changes on form.

Note:

  1. Validation take place between tags, so need to specify the ID
    of the Form or any other tags.
<formid="form2submit"></form> // Preferred
<divid=form2submit></div> // Not-Preferred.

For General Input Validation

  1. Input Fields should specify the type of validation.
<formmethod="post" id="form2submit" novalidate><div><label>Only Alpha</label><inputtype="text" data-allow="onlyAlpha" name="alpha"
data-message="<b style='color:green'>This field is required.</b>" required></div><div><label>String</label><inputtype="text" data-allow="string" data-message="This also required." data-allowSpecial="+-" name="string"
required></div><div><label>Pattern</label><inputtype="text" pattern="^[0-5]+$" data-allowSpecial="/-" name="pattern"></div><div><label>Number</label><inputtype="number" name="number" required></div><div><label>Min Validator</label><inputtype="text" name="myNumber" min="5" max="10" required></div><div><label>Email Validator</label><inputtype="email" name="email" required></div><div><labelfor="file">File</label><inputtype="file" requiredclass="form-control" id="file" data-extensions="png,jpeg,jpg" name="file"></div><div><label>Password</label><inputtype="password" name="password" data-check="repassword" id="password" required></div><div><label>Password</label><inputtype="password" name="password" data-check="repassword" id="password" required></div><div><label>List</label><selectname="list" required><optionvalue="item1">Item1</option><optionvalue="item2">Item2</option><optionvalue="item3">Item3</option></select></div><div><label>Description</label><textarearequiredname="desc"></textarea></div><div><inputtype="submit" value="Submit"></div></form>
  1. In form use novalidate to avoid browser interuptions.

    <formmethod="POST/GET/PUT/PATCH/DELETE" action="PATH-TO-HANDLE" id="form2submit" novalidate> ...
    ...
    </form>

Sample

// For Native & ES6 Javascript.varmyform=newjsValidator().init({form: 'form2submit',// #idforceFilter: true,message: {required: 'This field is required !',min: '<br><span style="color: red;">This field is less then the limit</span>',max: 'This field is exceeds the limit',password: 'Password doesn\'t match !',email: 'Invalid Email found !',file: 'Invalid File format given'}});

It Will listen the Submit event Automatically and initiating the validation checks. And based on response, it will allow to submit or throw messages.

License

Copyright (c) 2016 Shankar Thiyagaraajan

MIT License

About

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

Topics

Resources

Stars

8 stars

Watchers

4 watching

Forks

Releases

Packages

Contributors

Languages