HTML javascript valIdation not working

HTML javascript valIdation not working

本文关键字:working not valIdation javascript HTML      更新时间:2023-09-26

我有这个带有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>

此行缺少""enter the valid Mobile number";