Closed
Description
I just copy and paste, change object value and try to trigger errors...but result shows empty array...
please help, give me some clues... i was trapped by this in hours...thank you
----------- terminal info ---------------
[]
Validation succeed.
import {ValidationSchema, registerSchema, validate} from "class-validator";
export let UserValidationSchema: ValidationSchema = { // using interface here is not required, its just for type-safety
name: "myUserSchema", // this is required, and must be unique
properties: {
firstName: [{
type: "minLength", // validation type. All validation types are listed in ValidationTypes class.
constraints: [2]
}, {
type: "maxLength",
constraints: [20]
}],
lastName: [{
type: "minLength",
constraints: [2]
}, {
type: "maxLength",
constraints: [20]
}],
email: [{
type: "isEmail"
}]
}
};
registerSchema(UserValidationSchema);
const user = { firstName: "1", secondName: "1", email: "johnycage.com" };
validate("myUserSchema", user).then(errors => {
console.log(errors)
if (errors.length > 0) {
console.log("Validation failed: ", errors);
} else {
console.log("Validation succeed.");
}
});