【发布时间】:2016-05-19 20:41:45
【问题描述】:
我在 router.post 中有这段代码,它将在 ajax 的帮助下验证我的输入表单:
if(req.body.firstname === '' || req.body.firstname !== req.body.firstname.match(/\D+/g)[0]) {
console.log('AJAX ERROR: Firstname is empty and/or have a number.');
}
else if(req.body.captcha !== req.body.captcha.match(/^kettő$/igm) ||
req.body.captcha !== req.body.captcha.match(/^ketto$/igm) ||
req.body.captcha !== req.body.captcha.match(/^two$/igm)) {
console.log('AJAX ERROR: captcha is empty and/or the entered value is invalid.');
}
else {
console.log('AJAX ERROR');
};
预期输出:
- 如果
firstname为空,则在console.log中抛出错误 - 如果
firstname有数字,则在console.log中抛出错误 - 如果
captcha不等于kettő, ketto, Kettő, Ketto, KETTŐ, KETTO, two, Two, TWO答案,则在console.log中抛出错误 - 如果不满足这些要求,请抛出
else。
经验丰富的行为:
-
在验证
firstname之后,captcha总是向console.log抛出错误。firstname按预期工作。
在连续多次重新请求后,我也遇到了严重的延迟,并出现以下控制台错误:main-vanilla.min.js:1 POST http://127.0.0.1:3000/hu/form net::ERR_EMPTY_RESPONSE
【问题讨论】:
标签: javascript regex node.js forms express