1.0.23 • Published 4 years ago

simple-javascript-validator-test2 v1.0.23

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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

ValidationRule
requiredValue must be required
numberValue must be a number
emailValue must be an email
gtzeroSelect 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.