JavaScript不验证我的表单 函数validateForm(){ var x=document.forms[“Email”].value; var atpos=x.indexOf(“@”); var dotpos=x.lastIndexOf(“.”); 如果(atpos6) 其他的 { 警报(“至少需要6个字符!!”; 返回false; } var vl=document.forms[“Phno”].value; 对于(变量i=0;i10|vl.lenght

JavaScript不验证我的表单 函数validateForm(){ var x=document.forms[“Email”].value; var atpos=x.indexOf(“@”); var dotpos=x.lastIndexOf(“.”); 如果(atpos6) 其他的 { 警报(“至少需要6个字符!!”; 返回false; } var vl=document.forms[“Phno”].value; 对于(变量i=0;i10|vl.lenght,javascript,Javascript,(更新) 表单(注意“return validateForm();”而不是“validateForm()”: 注册 *函数注意GetElementById()而不是表单[]:* <form method="post" onsubmit="return validateForm();"> <center> <input style="padding: 5 10px;width:274px;height:44px;margin-bottom:

(更新)

表单(注意“return validateForm();”而不是“validateForm()”:


注册
*函数注意GetElementById()而不是表单[]:*

<form method="post" onsubmit="return validateForm();">
          <center> <input style="padding: 5 10px;width:274px;height:44px;margin-bottom:                                                                        10px;"  id="Email" name="Email" 

type="email" placeholder="Email"> 
           <input style="padding: 5 10px;width:274px;height:44px;margin-bottom: 10px;" id="Password" name="Password" 

type="Password" placeholder="Password">
           <input style="padding: 5 10px;width:274px;height:44px;margin-bottom: 10px;" id="Phno" name="Phno" 

type="phonenumber" placeholder="Phone No">
           <input style="padding: 5 10px;width:274px;height:44px;margin-bottom: 10px;" id="date" name="date" type="date" 

placeholder="DOB">
                   <button type="submit" style="border: 1px solid; background-color:#3079ed; width:274px;height:44px;" 

class="button"><b>Sign Up</b></button>      
</center>
</form>
函数validateForm(){
var x=document.getElementById(“电子邮件”).value;
var atpos=x.indexOf(“@”);
var dotpos=x.lastIndexOf(“.”);
如果(atpos=0)
{
警告(“不是有效的电子邮件地址!!”;
返回false;
}
var y=document.getElementById(“密码”).value;

if(y.lengthIt是因为您在电子邮件条件if(atpos)中返回false。您应该考虑使用正则表达式验证字符串,例如
/^[a-z@_\.]+$/i.test(vl)
可能会替换所有那些
|
表达式。您在那里有太多错误,我将更正并发布:)没有仍然跳过字段的其余部分仍然没有验证您可以发布表单吗?您应该使用getElementbyId il将立即更新它的工作状态我只是测试它:D
    <form method="post" onsubmit="validateForm()">
          <center> <input style="padding: 5 10px;width:274px;height:44px;margin-bottom:                                                                        10px;"  id="Email" name="Email" 

type="email" placeholder="Email"> 
           <input style="padding: 5 10px;width:274px;height:44px;margin-bottom: 10px;" id="Password" name="Password" 

type="Password" placeholder="Password">
           <input style="padding: 5 10px;width:274px;height:44px;margin-bottom: 10px;" id="Phno" name="Phno" 

type="phonenumber" placeholder="Phone No">
           <input style="padding: 5 10px;width:274px;height:44px;margin-bottom: 10px;" id="date" name="date" type="date" 

placeholder="DOB">
                   <button type="submit" style="border: 1px solid; background-color:#3079ed; width:274px;height:44px;" 

class="button"><b>Sign Up</b></button>      
</center>
</form>
<form method="post" onsubmit="return validateForm();">
          <center> <input style="padding: 5 10px;width:274px;height:44px;margin-bottom:                                                                        10px;"  id="Email" name="Email" 

type="email" placeholder="Email"> 
           <input style="padding: 5 10px;width:274px;height:44px;margin-bottom: 10px;" id="Password" name="Password" 

type="Password" placeholder="Password">
           <input style="padding: 5 10px;width:274px;height:44px;margin-bottom: 10px;" id="Phno" name="Phno" 

type="phonenumber" placeholder="Phone No">
           <input style="padding: 5 10px;width:274px;height:44px;margin-bottom: 10px;" id="date" name="date" type="date" 

placeholder="DOB">
                   <button type="submit" style="border: 1px solid; background-color:#3079ed; width:274px;height:44px;" 

class="button"><b>Sign Up</b></button>      
</center>
</form>
 function validateForm() {
var x = document.getElementById("Email").value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>x.length || x==="" ||x.indexOf(" ")>=0)
{
        alert("Not a valid e-mail address!!");
        return false;

}
var y = document.getElementById("Password").value;
if(y.length<6)
{
        alert("Minimum 6 Characters Required!!");
        return false;

}
var vl = document.getElementById("Phno").value;
for (var i = 0; i<vl.length; i++)
{
    if(isNaN(vl[i]))
    {
        alert("Enter a valid Phone Number!!");
        return false;
    }
}
if(vl.lenght!=10)
{
    alert("Enter a valid Phone Number!! ");
    return false;
}   

var d = document.getElementById("date").value;
if(d==="")
return false;

return true;
}