Currently I have html Code like this:
<!DOCTYPE html>
<html>
<body>
<p>Select an element</p>
<form action="/action">
<label for="fruit">Choose a fruit:</label>
<select name="fruit" id="fruit">
<option value="Banana">Banana</option>
<option value="Apple">Apple</option>
<option value="Orange">Orange</option>
</select>
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
And on the server side I want so check with the express validator if the fruit in the post request is either a banana, an apple or an orange. This is the code I have so far:
const{body} = require('express-validator');
const VALIDATORS = {
Fruit: [
body('fruit')
.exists()
.withMessage('Fruit is Requiered')
.isString()
.withMessage('Fruit must be a String')
]
}
module.exports = VALIDATORS;
How do I check if the string sent by the POST request is one of the required fruit?
.matches()
method like:.matches('Apple')
– Ouzel