Skip to main content
Version: Next

valiendCheck

With this method, you can validate several data together, create a schema, and with that schema, this method validates and returns the result.

Params

valiendCheck(inputs = {email,password,phoneNumber,username},options = {});
  • inputs → In this object, we put the data we want to validate

    inputs object

    It is not necessary to provide all these data. Pass any data you want to validate in the form of value to the desired key of that data.

  • options → In this parameter, we must pass the schema, we must create the schema using the schemaMaker method

schema maker

To create a schema, you must use the schemaMaker method This is how you can create a schema:

const schema = valiend.schemaMaker({
usernameSchema: {
validChars: ["_", "."],
},
passwordSchema: {
safePassword: true,
safePasswordStrictMode: true,
minPasswordScore: 50,
},
phoneNumberSchema: {
ignoreCountryCode: false,
},
});
  • validChars → The list of allowed characters in the username, by default its value is "_" and "." and you can give it your desired value here,Like what was in the isUsername method
  • safePassword → Whether to check the security of the password or not, the way to check the security of the password is done in the form of the isSafePassword method.
  • safePasswordStrictMode → Activating strict mode only works when you set safePassword to true, strict mode works exactly like isSafePassword.
  • minPasswordScore → If the safePassword key is activated, this key is useless, but otherwise you can specify the quality of the password by giving a number from 0 to 100 to this key, it works exactly like passwordQuality.
  • ignoreCountryCode → Not considering the country code is like the same option that is included in isPhoneNumber

Returns

{
result: false,
errors: [{username : "username not valid"},{ password: "password is not safe" }],
}
  • Object → An object that contains the final result and an array of existing errors. If there are no errors and result is true, the errors array is empty.

Usage

inputs = {
username: "@riankoc",
password: "aeromch@e3",
email: "arian.koochak@protonmail.com",
};
const schema = valiend.schemaMaker({
usernameSchema: {
validChars: ["_"],
},
passwordSchema: {
safePassword: true,
},
});
valiend.valiendCheck(inputs, schema);
/*
{
result: false,
errors: [{username : "username not valid"},{ password: "password is not safe" }],
}
*/
const inputs = {};
const schema = valiend.schemaMaker({
usernameSchema: {
validChars: ["_"],
},
passwordSchema: {
safePassword: true,
},
});
valiend.valiendCheck(inputs, schema);
/*
{
result: false,
errors: [],
}
*/
const inputs = {
username: "ariankoc",
password: "aeromch@e3",
email: "arian.koochak@protonmail.com",
};
const schema = valiend.schemaMaker({
usernameSchema: {
validChars: ["_"],
},
passwordSchema: {
safePassword : true,
},
});
valiend.valiendCheck(inputs, schema);
/*
{
result: false,
errors: [
{password : "password is not safe"}
],
}
*/
const inputs = {
username : 'ariankoc',
password : 'aeromch@e3',
email : 'arian.koochak@protonmail.com',
}
const schema = valiend.schemaMaker({
usernameSchema : {
validChars : ['_']
},
passwordSchema : {
minPasswordScore : 25,
}
})
valiend.valiendCheck(inputs, schema);
/*
{
result : true,
errors : [],
}
*/