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?
Latest version of express-validator solved this issue
req.assert('name',"Valid name is required!").optional().isName();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With