Giter VIP home page Giter VIP logo

js_tagvalidator's Introduction

TAG Validator

TAG Validator is a JavaScript script that makes easy the form validation using a clear sintax. It works using HTML5's data attributes for set the Validation Rules.

<input type="text" id="name"
                    data-validator="require max-length" 
                    data-max-length="20">

How to set up TAG Validator

First you need to include the script in the page. <script src="tagvalidator.js"/>

For set the Validation Rules there are two ways:

  • Writting the Rules directly in the HTML control
  • With JS Object

Writting the Rules (directly way)

The format is as follows: data-[TAG Name]="[rules]" data-validator="require numeric"

And just need to be added to the HTML control:

<input type="text" id="name" 
                    data-validator="require numeric">

Using JS Object

JavaScript Objects allows you configure all the HTML controls having all the information for validation in one places. Making future changes and debugging easy.

var settings = [
	{
		tag_name: "rules"
	}
]

Example:

var settings = [
	{
		id: "name",
		validator: "require"
	}, {
		id: "age",
		validator: "require numeric"
	}
]

Settings is an array of objects. For each control, one object. In each object, the ID property is mandatory, the others are optional. How to initialize the settings:

var base = new ValidatorSettings();
base.setSettings(settings);

This functions binds the settings in every HTML control.

TAGS

Tags are attributes for each HTML control that contains the information for validate it. Available TAGS:

  • ID
  • VALIDATOR
  • GROUP

RULES

The Rules indicates how the HTML has to be validated. Available RULES:

  • REQUIRE
  • NUMERIC
  • MAX_LENGTH
  • SAME
  • PASSWORD
  • PHONE
  • EMAIL

js_tagvalidator's People

Contributors

bassamhbj avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.