eagle-validator
A modern javascript object validation node package available on npmjs.com
Basic usage
a simple middleware for you
; { const valid = firstName: req phoneNumber: req email: req ; const invalid = valid; if invalid return resstatus400; return ;}
this will return simplified messages like:
for required field
firstName field is required
firstName should be a string
firstName should be greaterthan 2
firstName should be lessthan 19
firstName should be alphabetic
Basic abbrevations used
abbrevations | meaning | example |
---|---|---|
str() | string | 'hello' |
req() | required | 'world' |
min() | minimum characters | any |
max(3) | miximum characters | any |
number() | should be a number | 1-9 |
num() | only numbers in a string | 0-9 |
alpha() | should ba alphabets only | A-Z,a-z |
alphaNum() | mixture of alpha & nums | A-Z,a-z,0-9 |
bool() | should be a boolean | true |
email() | stictly email address | rswaib@gmail.com |