input-is
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:
; // const inputIs = require('input-is'); inputIs; // falseinputIs; // true
Functions:
- date
- datetime
- exactly
- filled
- float
- integer
- max
- min
- not
- number
- partOf
- phonenumber
- time
- url
- valid
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; // falseinputIs; // 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; // falseinputIs; // true
This function validates if a form input is a valid email
return value: boolean
inputIs; // falseinputIs; // true
exactly
This function validates if a form input is a exactly the same as a target
return value: boolean
inputIs; // falseinputIs; // true
filled
This function validates if a form input is filled, e.g. the value is minimum one character long
return value: boolean
inputIs; // falseinputIs; // true
float
This function validates if a form input is a valid float (not type number)
return value: boolean
inputIs; // falseinputIs; // true
integer
This function validates if a form input is a valid integer (not type number)
return value: boolean
inputIs; // falseinputIs; // true
max
This function validates if a form input is maximum the length of target
return value: boolean
inputIs; // falseinputIs; // true
min
This function validates if a form input is minimum the length of a target
return value: boolean
inputIs; // falseinputIs'value' 3; // true
not
This function validates if a form input is not like the target
return value: boolean
inputIs; // falseinputIs; // true
number
This function validates if a form input is a valid number (not type number)
return value: boolean
inputIs; // falseinputIs; // true
partOf
This function validates if a form input is part of a provided characterset
return value: boolean
inputIs; // falseinputIs; // true
phonenumber
This function validates if a form input is a valid phonenumber
return value: boolean
inputIs; // falseinputIs; // true
time
This function validates if a form input is a valid time
return value: boolean
inputIs; // falseinputIs; // true
url
This function validates if a form input is a valid url
return value: boolean
inputIs; // falseinputIs; // true
valid
This function validates form input to a regular expression
return value: boolean
inputIs; // falseinputIs; // true
LICENSE
MIT © Lukas Aichbauer