HTML javascript valIdation not working
HTML javascript valIdation not working
我有这个带有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
";
相关文章:
- $rootScope not working
- jQuery document.ready not working
- Javascript getElementsByTagName not working?
- JQuery.val( ) not working
- Tomcat websocket is not working
- Javascript JSON.parse not working
- NodeJS Multer is not working
- Regex not working
- Ember run.debounce not working
- AngularJs 1 not working
- document.getElementById.style.backgroundImage not working
- Rxjs5, distinct() is not working
- createOscillator noteOn not working
- Javascript - .getHours() not working
- Javascript setTimeout not working | onkeydown
- MongoDB $pull not working
- Express router.use not working
- JSONP not working
- window.opener not working in chrome & IE
- Backbone + RequireJS: Collection.each() is not working