I have installed and imported validator module in the node js file.
I want to validate the User's phone number using npm module "Validator" I have written the code as below but it is Not Working. It is inside of the schema
phone: {
type: Number,
required: true,
unique:true,
validate(value) {
if(!validator.isMobilePhone(value)){
throw new error ("Please enter valid phone number")
}
}
It is saving all the invalid phone numbers as well like jist : 1234.
How to solve this?