Using yarn:
yarn add xbrain-validate
Using npm:
npm install --save xbrain-validate
const schema = {
rules: {
username: {
required: true,
minLength: 2,
maxLength: 4,
},
password: {
required: true,
minLength: 5,
},
confirm_password: {
required: true,
minLength: 5,
equalTo: 'password',
},
value: {
min: 0,
max: 12,
},
birthDay: {
date: '< today, underAge 18, overAge 18',
},
},
messages: {
username: {
required: 'Username required.',
minLength: 'Your username must contain at least 2 characters.',
},
password: {
required: 'Password required.',
minLength: 'Your password must contain at least 5 characters.',
},
confirm_password: {
required: 'Enter your password again.',
minLength: 'Your password must contain at least 5 characters.',
equalTo: 'Your password confirmation does not match the password.',
},
},
};
const errors = validate.schema(schema, values);
- cnpj
- cpf
- date { underAge 18, overAge 18, > today, >= today, < today, <= today, > fieldX, >= fieldX, < fieldX, <= fieldX }
- equalTo
- hour
- hybridPhone
- IPv4
- match
- max
- maxLength
- min
- minLength
- notSunday
- notWeekend
- required
- url