Everyone says to use an array but I want to see how to would do it in a function.
I have something like this
<code>const checkPasswordConfirm = () => {
body('password-confirm').custom((value, { req }) => {
if(value !== req.body.password) {
throw new Error('Passwords confirmation does not match password')
}
})
}
</code>
<code>const checkPasswordConfirm = () => {
body('password-confirm').custom((value, { req }) => {
if(value !== req.body.password) {
throw new Error('Passwords confirmation does not match password')
}
})
}
</code>
const checkPasswordConfirm = () => {
body('password-confirm').custom((value, { req }) => {
if(value !== req.body.password) {
throw new Error('Passwords confirmation does not match password')
}
})
}
1
Here, you need to return true of validation passes
<code>enter code heconst { body } = require('express-validator');
const checkPasswordConfirm = () => {
return body('password-confirm').custom((value, { req }) => {
if (value !== req.body.password) {
throw new Error('Password confirmation does not match password');
}
return true; // Return true if validation passes
});
};
module.exports = checkPasswordConfirm;re
</code>
<code>enter code heconst { body } = require('express-validator');
const checkPasswordConfirm = () => {
return body('password-confirm').custom((value, { req }) => {
if (value !== req.body.password) {
throw new Error('Password confirmation does not match password');
}
return true; // Return true if validation passes
});
};
module.exports = checkPasswordConfirm;re
</code>
enter code heconst { body } = require('express-validator');
const checkPasswordConfirm = () => {
return body('password-confirm').custom((value, { req }) => {
if (value !== req.body.password) {
throw new Error('Password confirmation does not match password');
}
return true; // Return true if validation passes
});
};
module.exports = checkPasswordConfirm;re
2