Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

input-is

aichbauer108MIT2.1.1

Simple input validation

form, validation, input, valid, is, input-is

readme

input-is

Build Status Coverage Status

Simple input validation

Why?

Almost any project needs a form validation. This package simplifies your workflow.

Installation

npm i -S input-is

or

yarn add input-is

Usage

After installation you can import the package to your project and use a declarative way to validate your form inputs. The return value is always a boolean, e.g. true or false.

Here is a litte example:

import inputIs from 'input-is'; // const inputIs = require('input-is');

inputIs.email('hello'); // false
inputIs.email('example@mail.com'); // true

Functions:

date

Note: you have to pass the format of the date as second parameter to the function

This function validates if a form input is a valid date

return value: boolean

// valid formats:
// YYYY-MM-DD, MM-DD-YYYY,
// DD-MM-YYYY, YYYY/MM/DD,
// MM/DD/YYYY, DD/MM/YYYY,

inputIs.date('100/100/1000'); // false
inputIs.date('12/12/2017', 'DD/MM/YYYY'); // true

datetime

Note: you have to pass the format of the date as second parameter to the function

This function validates if a form input is a valid datetime

return value: boolean

// valid formats:
// YYYY-MM-DD hh:mm:ss, YYYY-MM-DD hh:mm,
// MM-DD-YYYY hh:mm:ss, MM-DD-YYYY hh:mm,
// DD-MM-YYYY hh:mm:ss, DD-MM-YYYY hh:mm,
// YYYY/MM/DD hh:mm:ss, YYYY/MM/DD hh:mm,
// MM/DD/YYYY hh:mm:ss, MM/DD/YYYY hh:mm,
// DD/MM/YYYY hh:mm:ss, DD/MM/YYYY hh:mm,

inputIs.datetime('12/12/2017'); // false
inputIs.datetime('12/12/2017 12:12:12', 'DD/MM/YYYY'); // true

email

This function validates if a form input is a valid email

return value: boolean

inputIs.email('example.mail.com'); // false
inputIs.email('example@mail.com'); // true

exactly

This function validates if a form input is a exactly the same as a target

return value: boolean

inputIs.exactly('this should be', 'exactly like this target'); // false
inputIs.exactly('exactly the same', 'exactly the same'); // true

filled

This function validates if a form input is filled, e.g. the value is minimum one character long

return value: boolean

inputIs.filled(''); // false
inputIs.filled('1'); // true

float

This function validates if a form input is a valid float (not type number)

return value: boolean

inputIs.float('1'); // false
inputIs.float('1.0'); // true

integer

This function validates if a form input is a valid integer (not type number)

return value: boolean

inputIs.integer('z'); // false
inputIs.integer('990'); // true

max

This function validates if a form input is maximum the length of target

return value: boolean

inputIs.max('value', 3); // false
inputIs.max('value', 5); // true

min

This function validates if a form input is minimum the length of a target

return value: boolean

inputIs.min('value', 6); // false
inputIs.('value', 3); // true

not

This function validates if a form input is not like the target

return value: boolean

inputIs.not('target', 'target'); // false
inputIs.not('value', 'target'); // true

number

This function validates if a form input is a valid number (not type number)

return value: boolean

inputIs.number('number'); // false
inputIs.number('1'); // true

partOf

This function validates if a form input is part of a provided characterset

return value: boolean

inputIs.partOf('z', 'part of ABC'); // false
inputIs.partOf('ABC', 'part of ABC'); // true

phonenumber

This function validates if a form input is a valid phonenumber

return value: boolean

inputIs.phonenumber('+12'); // false
inputIs.phonenumber('+1234567890'); // true

time

This function validates if a form input is a valid time

return value: boolean

inputIs.time('01:'); // false
inputIs.time('01:01'); // true

url

This function validates if a form input is a valid url

return value: boolean

inputIs.url('google.'); // false
inputIs.url('https://www.google.com'); // true

valid

This function validates form input to a regular expression

return value: boolean

inputIs.valid('google', /.at/); // false
inputIs.valid('hat', /.at/); // true

LICENSE

MIT © Lukas Aichbauer

changelog

2.1.1 - February, 04 2019

  • 600f086 Fix: regex of email and url (#6) (Lukas Aichbauer)

2.1.0 - October, 24 2018

  • 90b9292 Feat: add support for iso datetime (#5) (Lukas Aichbauer)

2.0.0 - September, 06 2018

  • 770da33 Chore: add changelog (#3) (Lukas Aichbauer)
  • 20e2ac9 Feat: new required param format for date and datetime (#2) (Lukas Aichbauer)
  • 68b4815 CI: add node version 8 (#1) (Lukas Aichbauer)

1.1.2 - June, 05 2017

  • 1d36fec v1.1.2 (aichbauer)
  • 659d85a Docs: update example (aichbauer)
  • 323852e Docs: update bagdes (rudolfsonjunior)
  • bbd9c54 Chore: update repo path (rudolfsonjunior)

1.1.1 - May, 09 2017

  • 5b27403 Chore: changed babel-plugin to dev dependencies (rudolfsonjunior)

1.1.0 - May, 09 2017

  • de9acbe CI: change from npm install to yarn (rudolfsonjunior)
  • 8fc1466 Test: add tests for require() (rudolfsonjunior)
  • 25011c7 Feat: add support for require() without default (rudolfsonjunior)

1.0.3 - May, 07 2017

  • edbba22 Chore: update .npmignore (rudolfsonjunior)

1.0.2 - May, 07 2017

  • a500576 Chore: add .npmignore (rudolfsonjunior)

1.0.1 - May, 06 2017

  • b3581b8 :bug: Fix: add correct readme (rudolfsonjunior)

1.0.0 - May, 06 2017

  • 0a8f1b7 :bug: Fix: change name (rudolfsonjunior)
  • 4df758c :memo: Docs: add travis ci and coveralls bagde (rudolfsonjunior)