目前我有这样的html代码:
<!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>
Run Code Online (Sandbox Code Playgroud)
在服务器端,我想通过快速验证器检查发布请求中的水果是否是香蕉、苹果或橙子。这是我到目前为止的代码:
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;
Run Code Online (Sandbox Code Playgroud)
如何检查POST请求发送的字符串是否是所需的水果之一?