【发布时间】:2016-09-06 06:00:19
【问题描述】:
我正在使用 javascript 验证来验证我的表单,但它无法正常工作,因为我在控制台屏幕上看到一个错误
“base.js:35 Uncaught SyntaxError: Unexpected identifier”。
我的javascript如下:
var user = {
signup : function() {
var firstname = document.signupform.first_name.value;
var email = document.signupform.email.value;
var password = document.signupform.password.value;
var confirmpassword = document.signupform.confirmpassword.value;
if (firstname == "")
{
alert("Please provide first name!")
document.signupform.first_name.focus();
}
else if (!validateEmail())
{
alert("Please provide valid email!")
document.signupform.email.focus() ;
}
else if (password == "")
{
alert("Please enter a valid password")
document.signupform.password.focus() ;
}
else if (password != confirmPassword)
{
alert("Passwords do not match.");
document.signupform.confirmpassword.focus() ;
}
else
{
return true
}
return false
}
validateEmail : function()
{
var emailID = document.signupform.email.value;
atpos = emailID.indexOf("@");
dotpos = emailID.lastIndexOf(".");
if (atpos < 1 || ( dotpos - atpos < 2 ))
{
return false;
}
return true;
},
}
【问题讨论】:
-
显示的代码具有无效的对象文字语法。在控制台中是否将行号显示为超链接?如果是这样,请单击它,它应该会突出显示有问题的特定标识符...
-
互联网上有很多关于有效电子邮件的主题。您可以检查这个答案,例如哪里是不错的正则表达式,您可以轻松复制粘贴 stackoverflow.com/questions/46155/…
标签: javascript validation email