JavaScript library to validate an object of values based on a set of given rules.
"use strict";
const {Validator} = require("@aminnairi/validator");
new Validator({secret: "required|string|password"}).validate({secret: "kitten123"});
$ npm install aminnairi/validator
$ npm uninstall @aminnairi/validator
Instanciate a new validator.
new: (rules: Record<string, string>) => Validator;
Customize the error messages generated by the validator.
setTranslations: (translations: Record<string, Record<string, string>>) => void;
Return properties that do not match the rules set for the created validator.
validate: (data: Record<string, any>) => null | Record<string, string[]>;
Check if the value is a date.
See example/date.js
.
Check if the value is not equal to another.
See example/different.js
.
Check if the value is a valid email.
See example/email.js
.
Check if the value is include inside a set of values.
See example/in.js
.
Check if the value is an integer.
See example/integer.js
.
Check if a number is lower or equal to a given one. This also checks if a string has a length of at most a given length.
See example/maximum.js
.
Check if a number is greater or equal to given one. This also checks if a string has a length of at least a given length.
See example/minimum.js
.
Check if a value has at least one lower and uppercase letter, one digit, one symbol and at least 8 characters.
See example/password.js
.
Check if a value is present and is not null.
See example/required.js
.
Check if a value is equal to another.
See example/same.js
.
Check if a value is of type string.
See example/string.js
.