Skip to content

Latest commit

 

History

History
71 lines (49 loc) · 1.56 KB

readme.md

File metadata and controls

71 lines (49 loc) · 1.56 KB

Simple Javascript Validator

Not much, but it's an honest work! (wink)

This package aims to validate the input data in javascript using the most common validation rules.

Installation

npm install simple-javascript-validator

Validation Rules

Validation Rule
required Value must be required
number Value must be a number
email Value must be an email
gtzero Select tag must have a value

gtzero - Because select tag's initial value is zero as shown in the example below:

<select>
  <option value="0" selected="selected">- select -</option>
  <option value="1">Admin</option>
  <option value="2">Guest</option>
</select>

How To Use

Please run the index.html file

<script src="simple-javascript-validator.min.js"></script>

var full_name     = document.getElementById("name").value;
var age           = document.getElementById("age").value;
var email_address = document.getElementById("email_address").value;
var role          = document.getElementById("role").value;


var validateData = {
  name  : full_name + '|required',
  age   : age + '|required,number',
  email : email_address + '|required,email',
  role  : role + '|gtzero'
};

var errors = validateInputs(validateData);

if(errors){
  console.log(errors);

  //toastr['error'](errors);

  return false;
}

License

The MIT License

Support

You can ask for support by emailing kapitannwel a t g m a i l d o t c o m

Donate

Use this for free, donation is optional.