This is basically aimed to validate forms in reactjs.
npm i js-object-validation
or
npm install js-object-validation
yarn add js-object-validation
Pure JS
Customizable messages
No dependencies
Easy to use.
import Validator from "js-object-validation";
try{
const objectToValidate = {
email: "sbamniya23",
password: "12"
}
const validations = {
email: {
email: true,
},
password: {
minlength: 8,
}
}
const messages = {
email: {
email: "Email should be valid email",
},
password: {
minlength: "Password should be at least 8 charater long",
}
} // this is optional
const {isValid, errors} = Validator(objectToValidate, validations, messages);
if(isValid){
<!-- object has passed all validations -->
} else {
<!-- object has some error -->
console.log(errors)
}
} catch(error) {
console.log(error)
}
required
numeric
maxnumber
minnumbers
alphanumeric
alpha
maxlength
minlength
equal
password
username
url
Fixed Issue #1
Added Validations for Password and Username
Added typescript defination and removed ENUM for clear management
If you have any new update/idea feel free to contact.