Node Js Express validator Check if field is numeric only if it is not empty
You need to set the checkFalsy
option for optional
to allow defined-but-empty values:
request.checkBody({
'product_price': {
optional: {
options: { checkFalsy: true }
},
isDecimal: {
errorMessage: 'The product price must be a decimal'
}
}
});
EDIT: the documentation has been moved since posting this answer, it can now be found here.