1.0.13 • Published 2 years ago

@haloriyan/validator v1.0.13

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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
  • email
  • min:length
  • max:length
  • same:another_data

datas (array)

pass your data to validate

Make sure the position is same within the rule

Contribute

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago