Is there a condensed way to do this validation on nodejs
//inbound express request
{ "myVal":"abcdefghij" }
/* first test if value exists,
then if it fails a regex return an error & exit function
if pass then continue
*/
// ... logic to get express.post(...=> {
if (( req.body.myVal == null ){
// no value, send error response and exit function
}else{
const inVar = req.body.myVal;
if ( inVar ){
const regex = /^([a-j0-9]){1,11}$/;
if(regex.test(inVar ) == false){
res.send({ error: "failed regex" });
res.end();
return;
}
... else continue