Giter Club home page Giter Club logo

if.js's Introduction

if.js

(v0.1.0)

if.js is a fast and effective validator library. It helps to validate e-mail, phone number, date and expressions. Please don't hesitate to share your thoughts.

Demo link : https://codepen.io/imagets/pen/XpVbKr

Before getting started

Here are some points about this validator ;

  • It checks if your input has "if" attribute.
  • It gives class names to directly to the input or element.
  • If input has "require" attribute, it will check on start. That means you'll see "success" or "error" classes on start.
  • You can write if attribute on form element as well. It checks all form inputs and gives class to form element if ALL elements are valid. You can check form's validation with this : if="this.valid"

You can input if.js with this code :

_if.init();

Also if.js has two argument, they are elements and options. You can set them like that :

_if.init('input, select', {
    timeout : 50
});

Validate with expression

You can enable if.js with this way ;

<input if="this.value">

If.js checks all elements if they had "if" attribute on them. You can write expression in this attribute to validate your input or you can check it's type to validate if it's email, phone etc.

Here is another example ;

<input if="this.length < 12">

In this example, as you can see, it counts it's character length and if this input has not less than 12 character, you'll see that input is not validated. In expression mode, you can use "length", "value" and "checked" attributes.

Validate with type

If.js checks element's potentiel types when they trigger. With this way, you'll be able to check if it's email, phone or full name.

Here is an example for type validation ;

<input if="this.type == 'email'">

As you can see, it checks if it's type is email or not.

Another example to check if it's phone ;

<input if="this.type == 'phone'">

Style

You can set your input validation styles on if.js init. Here is a code snippet to set classes.

_if.init('input, select', {
    class : {
		success : 'successClassName',
		error : 'errorClassName'
	}
});

Options

_if.init('input, select', {
    timeout : (integer),
    validateOnSubmit : (boolean)
});

License

MIT

if.js's People

Contributors

devcem avatar

Stargazers

Enver Yasar avatar Yunus Emre Özdiyar avatar

Watchers

James Cloos avatar  avatar

Forkers

incendies

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.