现在,我检查了电子邮件地址的有效性:
app.js
var express = require('express');
var app = express();
app.set('views', 'cloud/views');
app.set('view engine', 'ejs');
app.use(express.bodyParser());
app.get('/', function(req, res) {
res.render('home');
});
app.post('/', function(req, res) {
var Email = Parse.Object.extend("UserEmail");
var email = new Email({ email: req.body.EMAIL });
var temp =req.body.EMAIL;
if (temp.match(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)){
email.save().then(function(email) {
res.render('home', { message: '1' });
}, function(email) {
res.send('Oops, something went wrong!');
});}
else{res.render('home', { message: '2' });}
});
app.listen();
但问题是有可能再次写入相同的地址,但如果存在这样的地址,则在页面上显示一条消息: 如果不是很难解释如何添加验证?