1.0.13 • Published 2 years ago
@haloriyan/validator v1.0.13
Validator
Validate any data before sending to backend. Created to solve my own problem when I used React Native, without this package I need to check manually
Installation
npm i @haloriyan/validator
Usage
import Validator from '@haloriyan/validator';
let email = "riyan.satria.619@gmail.com";
let password = "supersecretpassword";
let passwordRetype = "notsecretpassword";
Validator({
email: 'required|email',
password: 'required|min:6|max:12',
passwodRetype: 'required|min:6|max:12|same:password'
}, [email, password, passwordRetype])
.then(() => {
// all data valid, continue to use fetch or axios
})
.catch(errors => {
console.log('some data was not correct', errors);
})
Arguments
rules
(object)
Define all the rules you need
Available rules :
- required
- min:
length
- max:
length
- same:
another_data
datas
(array)
pass your data to validate
Make sure the position is same within the rule