有人可以检查我的javascript代码,如果它们是正确的吗?我无法看到电子邮件提醒。我尝试点击提交按钮,但在提醒名称后,电子邮件无效。
function doValidate()
{
if (document.appointment.requiredname.value =="")
{
alert("Please put your name");
document.appointment.requiredname.focus();
return false;
}
var readmail = document.appointment.requiredemail.value;
var checkatsymbol = readmail.indexof("@");
var checkdotsymbol = readmail.lastindexof(".");
if (checkatsymbol < 1 || checkdotsymbol+2>=readmail.length )
{
alert("Please put the correct email address");
document.appointment.requiredemail.focus();
return false;
}
if (document.appointment.requiredphone.value =="" )
{
alert("Please put your phone");
document.appointment.requiredphone.focus();
return false;
}
if (document.appointment.requireddate.value =="" )
{
alert("Please put your appointment date as DD/MM/YYYY");
document.appointment.requireddate.focus();
return false;
}
if (document.appointment.requiredtime.value =="")
{
alert("Please put your appointment time as HH:MM AM/PM");
document.appointment.requiredtime.focus();
return false;
}
return ( true );
}
答案 0 :(得分:0)
您必须从return false;
条件中移除if
才能在函数中执行以下代码
答案 1 :(得分:0)
wirte'indexOf'不'indexof'替换:
var checkatsymbol = readmail.indexof("@");
var checkdotsymbol = readmail.lastindexof(".");
with:
var checkatsymbol = readmail.indexOf("@");
var checkdotsymbol = readmail.lastindexOf(".");
答案 2 :(得分:0)
Javascript区分大小写。
var checkatsymbol = readmail.indexof("@");
var checkdotsymbol = readmail.lastindexof(".");
应该是:
var checkatsymbol = readmail.indexOf("@");
var checkdotsymbol = readmail.lastIndexOf(".");
答案 3 :(得分:0)
var x=document.appointment.requiredemail.value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert("Not a valid e-mail address");
return false;
}
此验证电子邮件的代码段应该有效!!
答案 4 :(得分:0)
你应该前往CodeReview,一个StackExchange论坛