我已经为 html 表单编写了一个小代码,并尝试使用 javascript 对其进行验证,但它无法正常工作,甚至没有给出任何错误......我没有得到背后的问题......我已经看到 [javascript 简单验证不是在职的?
这是我的代码..
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>A simple Input Form</title>
<script type="text/javascript">
function validateEmail() {
//var emailID = document.myForm.email.value;
if(!validateNonEmpty(inputField, helpText))
return false;
return validateRegEx(/^\d{2}\/\d{2}\/\d{4}$/, inputField.value, helpText,
"please enter an email address i.e. johndoe@acme.com");
}
function validatedob(inputField, helpText){
if(!validateNonEmpty(inputField, helpText))
return false;
return validateRegEx(/^\d{2}\/\d{2}\/\d{4}$/, inputField.value, helpText,
"please enter an email address i.e. johndoe@acme.com");
}
function age(){
var currentDate = new Date()
var day = currentDate.getDay()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
}
function formValidate(){
if( document.myForm.dob.value == "" )
{
alert( "Please provide your date of birth!" );
document.myForm.dob.focus() ;
return false;
}
else {
var dateformat = validatedate();
if (dateformat == false)
{
return false;
}
}
if( document.myForm.email.value == "" )
{
alert( "Please provide your Email!" );
document.myForm.email.focus() ;
return false;
}else{
var ret = validateEmail();
if( ret == false )
{
return false;
}
}
if (document.myForm.age.value="")
{
alert("please provide your age");
document.myForm.age.focus();
return false;
}
else
{
var ageformat = validateage();
if (ageformat == false)
{
return false;
}
}
}
</script>
</head>
<body>
<div id="left">
<input type="button" value="previous">
<img src="/images/jump2" alt="Just-in-time" />
</div>
<input type="button" value="next">
<form name="myForm" method="post" action="success.html" onsubmit="formValidate();">
Date of Birth: <input id="dob" type="text" name="dob" size=10><br>
Age: <input id="age" type="text" name="age"><br>
Email: <input id="email" type="text" name="email"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>