我正在使用 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;
},
}
最佳答案
您的代码似乎在 validateEmail
之前缺少 ,
你应该在最后删除 ,
正如@nnnnnn 在下面的评论中提到的,使用 validateEmail()
将不起作用 - 将其替换为 this.validateEmail()
请注意,您验证电子邮件的方法不是很好,还传递了无效的电子邮件地址
关于javascript 电子邮件验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39341592/