HTML javascript验证不起作用

HTML javascript验证不起作用,javascript,validation,Javascript,Validation,我有这个带有javascript的html验证表单,但我不知道为什么它不起作用。它现在应该在按下按钮时计算两个文本框的值。然而,一切都没有发生。代码: <html> <head> <title>Form Validator</title> <script type="text/javascript"> //script here function Validate() { var numbers = /^[0-9]+$/; va

我有这个带有javascript的html验证表单,但我不知道为什么它不起作用。它现在应该在按下按钮时计算两个文本框的值。然而,一切都没有发生。代码:

<html>
<head>

<title>Form Validator</title>


<script type="text/javascript">
//script here

function Validate()
{
var numbers = /^[0-9]+$/;
var emailRegex = /^[A-Za-z0-9._]*\@[A-Za-z]*\.[A-Za-z]{2,5}$/;
var     fname  = document.myform.FullName.value,        
        fmobile = document.myform.Mobile.value,
        femail = document.myform.Email.value,
        fpass1 = document.myform.pass1.value,
        fpass2 = document.myform.pass2.value,   
        faddress = document.myform.Address.value;

if( fname == "" )
   {
     document.myform.FullName.focus() ;
     document.getElementById("errorBox").innerHTML = "enter the name";
     return false;
   }

    if (fmobile == "" )
    {
        document.myform.Mobile.focus();
        document.getElementById("errorBox").innerHTML = "enter the Mobile Number";
        return false;
     }else if(!numbers.test(fmobile)){
        document.myform.Mobile.focus();
        document.getElementById("errorBox").innerHTML = "enter the valid Mobile number";
        return false;
     }

          if (femail == "" )
    {
        document.form.Email.focus();
        document.getElementById("errorBox").innerHTML = "enter the email";
        return false;
     }else if(!emailRegex.test(femail)){
        document.form.Email.focus();
        document.getElementById("errorBox").innerHTML = "enter the valid email";
        return false;
     }


   if (fpass1 == "" )
    {
        document.myform.pass1.focus();
        document.getElementById("errorBox").innerHTML = "enter the Password";
        return false;
     }else if(fpass1.length > 8){
        document.myform.pass1.focus();
        document.getElementById("errorBox").innerHTML = "Password must be greater than 8 length";
        return false;
     }

      if (fpass2 == "" )
    {
        document.myform.pass2.focus();
        document.getElementById("errorBox").innerHTML = "enter the Confirm Password";
        return false;
     }


     if(fpass1 !=  fpass2){
         document.myform.enterEmail.focus();
         document.getElementById("errorBox").innerHTML = "Passwords are not matching, re-enter again";
         return false;
         }


              if (faddress == "" )
    {
        document.myform.Address.focus();
        document.getElementById("errorBox").innerHTML = "enter the Address";
        return false;
     }

         if(fname != '' && fmobile != '' && femail != '' && fpass1 != '' && fpass2 != '' && faddress != '' ){
            document.getElementById("errorBox").innerHTML = "form submitted successfully";
            }



}


</script>// script ends here
</head>
<body>
<form action="" name="myform" method="post" onsubmit="return Validate()" style="text-align:-moz-center;">
 // my html simple form start from here
<table cellspacing="2" cellpadding="2" border="0" >
<tr>
    <td align="right">Full Name</td>
    <td><input type="text" name="FullName"></td>
</tr>
<tr>
    <td align="right">Mobile</td>
    <td><input type="text" name="Mobile"></td>
</tr>
<tr>
    <td align="right">Email</td>
    <td><input type="text" name="Email"></td>
</tr>

<tr>
    <td align="right">Password</td>
    <td><input type="text" name="pass1"></td>
</tr>

<tr>
    <td align="right">Confirm Password</td>
    <td><input type="text" name="pass2"></td>
</tr>

<tr>
    <td align="right">Address</td>
    <td><textarea cols="20" rows="5" name="Address"></textarea></td>
</tr>


<tr>
    <td align="right"></td>
    <td><input type="submit" value="Submit" "> <div id="errorBox"></div></td>
</tr>
</table>
</form>
</body>
</html>

表单验证程序
//这里的脚本
函数验证()
{
变量数=/^[0-9]+$/;
var emailRegex=/^[A-Za-z0-9.\]*\@[A-Za-z]*\.[A-Za-z]{2,5}$/;
var fname=document.myform.FullName.value,
fmobile=document.myform.Mobile.value,
femail=document.myform.Email.value,
fpass1=document.myform.pass1.value,
fpass2=document.myform.pass2.value,
faddress=document.myform.Address.value;
如果(fname==“”)
{
document.myform.FullName.focus();
document.getElementById(“errorBox”).innerHTML=“输入名称”;
返回false;
}
如果(fmobile==“”)
{
document.myform.Mobile.focus();
document.getElementById(“errorBox”).innerHTML=“输入手机号码”;
返回false;
}否则如果(!number.test(fmobile)){
document.myform.Mobile.focus();
document.getElementById(“errorBox”).innerHTML=“输入有效的手机号码”;
返回false;
}
如果(femail==“”)
{
document.form.Email.focus();
document.getElementById(“errorBox”).innerHTML=“输入电子邮件”;
返回false;
}否则,如果(!emailRegex.test(femail)){
document.form.Email.focus();
document.getElementById(“errorBox”).innerHTML=“输入有效电子邮件”;
返回false;
}
如果(fpass1==“”)
{
document.myform.pass1.focus();
document.getElementById(“errorBox”).innerHTML=“输入密码”;
返回false;
}否则如果(fpass1.length>8){
document.myform.pass1.focus();
document.getElementById(“errorBox”).innerHTML=“密码长度必须大于8”;
返回false;
}
如果(fpass2==“”)
{
document.myform.pass2.focus();
document.getElementById(“errorBox”).innerHTML=“输入确认密码”;
返回false;
}
如果(fpass1!=fpass2){
document.myform.enterEmail.focus();
document.getElementById(“errorBox”).innerHTML=“密码不匹配,请重新输入”;
返回false;
}
如果(faddress==“”)
{
document.myform.Address.focus();
document.getElementById(“errorBox”).innerHTML=“输入地址”;
返回false;
}
如果(fname!=''&&fmobile!=''&&femail!=''&&fpass1!=''&&fpass2!=''&&faddress!=''){
document.getElementById(“errorBox”).innerHTML=“表单已成功提交”;
}
}
//脚本到此结束
//我的html简单表单从这里开始
全名
可移动的
电子邮件
暗语
确认密码
住址

缺少一个“在这一行
”输入有效的手机号码

这是他问题的答案。按钮不起作用,因为他错过了关闭字符串…好的,但是这样的问题不应该被回答。改为标记。OP应该学会使用调试器。我不知道。谢谢!