mysql - 我有数组对象,想验证一些文件,如电子邮件、联系人编号
问题描述
我正在从req.body
(数组对象数据)获取输入数据并尝试验证某些文件,例如email
, contactno
,但我不知道为什么我无法验证这些字段。
我尝试了各种方法,但没有成功。
请检查我的代码并尽快回复我必须尽快完成
addTickets : async function(req,res){
var data = [req.body];
var eventid = req.body.eventid;
var catid = req.body.ticketcategoryid;
var num = Math.floor(Math.random() * 90000) + 10000;
event_data = await Event.findOne({
where:{
id:eventid
}
});
if(event_data){
ticket_data = await Tickets.findOne({
where:{
id:catid
}
});
if(ticket_data){
req.check('email').isEmail().withMessage('Please enter valid email');
req.check('contactno').notEmpty().withMessage('Please enter your contact no');
var error = req.validationErrors();
if (error) {
return fun.returnResponse(res,false,400,fun.checkRequired(error).message);
return false;
}
else{
await con.query('INSERT INTO table SET ?', data, function (error, results, fields) {
if (error) throw error;
var msg = {
from: "abc@gmail.com", // sender address
subject: "Hello ✔", // Subject line
text: "Hello This is an auto generated Email for testing from node please ignore it ✔", // plaintext body
cc: "*******"
// html: "<b>Hello world ✔</b>" // html body
}
var maillist = [
'xyz@gmail.com',
'a.bussa@gmail.com',
'b.gawri@gmail.com',
];
// var sendto = data.email;
maillist.forEach(function (to, i , array) {
msg.to = to;
transporter.sendMail(msg, function (err) {
if (err) {
console.log('Sending to ' + to + ' failed: ' + err);
return;
} else {
console.log('Sent to ' + to);
}
res.end(JSON.stringify(results));
});
});
});
}
}
else{
return fun.returnResponse(res,false,204,"Ticket not found");
return false;
}
}
else{
return fun.returnResponse(res,false,204,"Event not found");
return false;
}
//console.log(ticket_data);
}
解决方案
推荐阅读
- r - 如何根据时间对象是否位于其他两个时间对象之间来制作分类变量
- android - 如何特别在设备 API 级别 25、26、27 上以编程方式结束来电
- html - 如何
- neo4j - 三角形计数/聚类 Neo4j
- ios - 让手机过于频繁地振动对硬件来说是不是很危险?
- javascript - node.js中的错误“意外令牌”是什么意思,以及如何删除它
- python - PyGtk gi 在图像小部件中使用 cv2 显示图像
- python - 使用 Tkinter 绘制 GUI 会抛出“NameError”
- jmeter - Taurus/JMeter < 1ms 粒度?
- android - Android MapsActivity - onclick 重新加载活动