Reputation: 12293
I am using express-validator for validation.
I have some parameters which are not mandatory like name.
I want to validate the parameter only if was exists, else no need to validate.
I have got a solution like
if(parameter){
req.assert('name',"Valid name is required!").isName();
}
Is there any better solution than this?
Upvotes: 5
Views: 13000
Reputation: 12293
Latest version of express-validator solved this issue
req.assert('name',"Valid name is required!").optional().isName();
Upvotes: 20