Skip to content

A simple, extendable form validation library without any dependencies

License

Notifications You must be signed in to change notification settings

moeenn/validator.js

Repository files navigation

Validator.js

A simple library for validating HTML forms. (because I hate jQuery)

Usage

<form id="sample_form">
  <fieldset>
    <label for="name">Name</label>
    <input
      for="name"
      type="text"
      data-required
      data-alpha
      data-minlength="5"
      data-same="password"
    />
  </fieldset>
</form>
import validate from '../dist/validator.min.js';

const form = document.querySelector('#sample_form');

form.addEventListener("submit", (e) => {
  e.preventDefault();

  const is_valid = validate(e.target);
  console.log("Is Form Valid?", is_valid);
});

See the Demo folder for a full example.

TODO

  • Update minification script to minify the bundle (i.e. all output .js files)
  • When value is read from the form, its value should be trimmed
  • Implement validation hierarchy e.g. If a required field is not filled out, don't run any other validators on it

Releases

No releases published

Packages

No packages published