All Projects → gocanto → easiest-js-validator

gocanto / easiest-js-validator

Licence: MIT License
The easiest way to validate your forms without 3rd party packages

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Labels

Projects that are alternatives of or similar to easiest-js-validator

wily
Build Node.js APIs from the command line (Dead Project 😵)
Stars: ✭ 14 (-73.58%)
Mutual labels:  validator
validation
A validation library for PHP that uses the notification pattern
Stars: ✭ 27 (-49.06%)
Mutual labels:  validator
amazon-ecs-exec-checker
🚀 Pre-flight checks for ECS Exec
Stars: ✭ 364 (+586.79%)
Mutual labels:  validator
laravel-vatvalidator
Package to validate a vat id via the api of the european union (vies)
Stars: ✭ 15 (-71.7%)
Mutual labels:  validator
bpmnlint
Validate BPMN diagrams based on configurable lint rules.
Stars: ✭ 82 (+54.72%)
Mutual labels:  validator
validation
Aplus Framework Validation Library
Stars: ✭ 99 (+86.79%)
Mutual labels:  validator
ird-nz
Checksum validator for New Zealand's IRD/GST number.
Stars: ✭ 15 (-71.7%)
Mutual labels:  validator
ty
Here is a schema checker which can return well typed results. Tell your friends!
Stars: ✭ 21 (-60.38%)
Mutual labels:  validator
UE4-BUIValidator
UE4 UI Texture Validator Plugin
Stars: ✭ 48 (-9.43%)
Mutual labels:  validator
Maat
Validation and transformation library powered by deductive ascending parser. Made to be extended for any kind of project.
Stars: ✭ 27 (-49.06%)
Mutual labels:  validator
persianize-node
Persianize is set of nodejs tools for validating and converting data to correct Persian.
Stars: ✭ 13 (-75.47%)
Mutual labels:  validator
denetmen
useful micro check library for Crystal Language.
Stars: ✭ 23 (-56.6%)
Mutual labels:  validator
node-input-validator
Validation library for node.js
Stars: ✭ 74 (+39.62%)
Mutual labels:  validator
crystal-validator
💎 Data validation module for Crystal lang
Stars: ✭ 23 (-56.6%)
Mutual labels:  validator
pyvaru
Rule based data validation library for python 3.
Stars: ✭ 17 (-67.92%)
Mutual labels:  validator
schema
SpaceAPI JSON schema files.
Stars: ✭ 20 (-62.26%)
Mutual labels:  validator
Saudi-ID-Validator
Saudi-ID-Validator (Swift, Kotlin, Java, Go, JS, Python, TypeScript, PHP, Scala, ruby, c#, vb, SQL)
Stars: ✭ 53 (+0%)
Mutual labels:  validator
notional
Full Documentation of Notional's systems
Stars: ✭ 31 (-41.51%)
Mutual labels:  validator
filter
Go语言的数据过滤包,由 数据输入、格式化、校验、输出 几个部份组成。
Stars: ✭ 22 (-58.49%)
Mutual labels:  validator
openui5-validator
A library to validate OpenUI5 fields
Stars: ✭ 17 (-67.92%)
Mutual labels:  validator

Easiest JS Validator

Demo Version Downloads Downloads License

It is a simple library ready to pull in into your project. Its goal is to provide an easy way to validate HTML forms without the headache of adapting any other complicated packages. Also, it was written in es2015, so you can get your feet wet with this amazing new way of working with JS.

Installation

To install this package you just need to open your console line and type npm i easiest-js-validator. If there is a problem during the installation, you can try again using the force param as so npm i -f easiest-js-validator

Gettings started

First of all, you will have to import the library into the file where you are operating. As so,

import Validator from 'easiest-js-validator';

Take a look at the example published.

illustration

example

Also, you will be able to see the online DEMO

Validation rules array

This array contains all the information about the form fields that you want to be validated where its keys are the same as your form object, As so:

<!-- input example is linked through VUEJS -->
<input type="text" v-model = "profile.first_name">
//rules object
rules: {
     first_name: 'required,alpha',
     last_name: 'required,alpha',
     email: 'required,email',
     address: 'required',
}

Implementation

//form object
profile: {
     first_name,
     last_name,
     email,
     address,
}

Implementation

Invoke the validator class

At this point, we just have to call the static method make into the validator class and pass the info which it will operate. As so,

let validate = Validator.make(profile, rules, messages);

Where messages will be the responsible of bringing the language into the class, in order for it to offer a better output, such as field is required, email is not valid, etc. It is important to know that messages have to meet the same structure as profile object.

//messages object example
messages: {
     first_name: 'required',
     email: 'must have a valid format'
}

Implementation

If there were errors

If there were errors, you will have an associative array using how reference the exactly field that does not meet the rules. as so,

errors = [
    first_name: "The field is required.",
    last_name: "The field is required.",
    email: "The email field must be a valid email address.",
    address: "The field is required."
]

Implementation

Now, you have access to the validation messages and can proceed as you want.

How can I see if my field has errors?

This is easy enough. You only have to check the returned array and show the result on the form in the best way for you. As so,

hasError: function (key)
{
     return typeof errors[key] !== 'undefined';
}

if (hasError('first_name')) {
     console.log(errors['first_name'])
}

You can see the demo on DEMO

Features

You will be able to validate you forms againts any of this rules:

  • url
  • integer
  • numeric
  • alphaNum
  • email
  • alpha
  • required
  • digits
  • length
  • blank
  • dateISO
  • phoneNumber

Summary

In spite of the demo was written in vuejs, you will be able to pull in the validator class under any other js framework

If you have any question, shoot me an email. I will be glad of helping you out.

Contributing

Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.

License

The MIT License (MIT). Please see License File for more information.

How can I thank you?

Why not star the github repo? I'd love the attention! Why not share the link for this repository on Twitter? Spread the word!

Don't forget to follow me on twitter!

Thanks!

Gustavo Ocanto. [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].