Complete the code to import the express-validator check function.
const { [1] } = require('express-validator');The check function is imported from express-validator to define validation rules.
Complete the code to create a custom validator that checks if a value is an even number.
check('number').custom(value => value [1] 2 === 0);
The modulo operator % is used to check if the number is divisible by 2 with no remainder, meaning it is even.
Fix the error in the custom validator to correctly reject odd numbers with an error message.
check('number').custom(value => { if (value [1] 2 !== 0) { throw new Error('Number must be even'); } return true; });
The modulo operator % is needed to check if the number is not divisible by 2.
Fill both blanks to create a custom validator that checks if a username starts with a capital letter and is at least 3 characters long.
check('username').custom(value => { if (!(/^[2]/[1](value))) { throw new Error('Username must start with a capital letter'); } if (value.length < 3) { throw new Error('Username must be at least 3 characters'); } return true; });
The test method checks if the string matches the regular expression /^[A-Z]/, which means it starts with a capital letter.
Fill all three blanks to create a custom validator that checks if an email ends with '.com' and contains '@', and throws an error if not.
check('email').custom(value => { if (!value[1]('@')) { throw new Error('Email must contain @'); } if (!(/\.[3]$/[2](value))) { throw new Error('Email must end with .com'); } return true; });
The includes method checks if '@' is present. The test method checks if the string ends with '.com' using the regex /\.com$/.