JSPM

input-validation

1.0.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q43152F
  • License ISC

Very simple universal input validation module

Package Exports

  • input-validation

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (input-validation) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

input-validation

Build Status

Very simple universal input validation module

This module has zero dependencies, is extensible and uses data attributes to target validation conditions

Getting Started

1. Installation (node)

npm install input-validation

2. Examples

    var validatior require('input-validation'),
        handlers = {
            blur: function(target) {
                target.className = validator.validate(target) ? '' : 'invalid';
            }
        }
   
    <input name="email" data-required data-valid-email onblur="handlers.onblur(this)">
  • data-required The user must supply some value to for the input to be valid
    <input data-required>
  • data-valid-email The user must supply a loosely valid email for the input to be valid
    <input data-valid-email>

Adding new validators

When extending input validation with new validators use camelCase without 'data' when specifying the attribute name.

    
    var validatior require('input-validation');
    
    validator.add('greaterThanTen', function(value) {
        return value !== undefined && parseInt(value,10) > 10;
    })
    

The user must supply an int value greater than 10

    <input data-greater-than-ten>

Copyright (c) 2015-2016 Anycode lee@anycode.io

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.