Where am I going wrong? I can get the javascript to validate that an email address has been entered, but not that the name and comments box are not empty. Can you please help?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Javascript Form Validation</title>
<script src="formvalidationjs.js"></script>
</head>
<body>
<h1>Contact Us</h1>
<form name='contactform' onSubmit="return validateform();">
<label for='name'>Name: </label></li> <li><input type="text" name="name" /></br>
<label for='email'>Email: </label></li> <li><input type="email" name="email" /></br>
<label for='phone'>Phone: </label></li> <li><input type="text" name="phone" /></br>
</br><label for='comment'>Comments: </label></li> <li><input type="text" name="comment" />
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
</body>
</html>
JavaScript code
function validateform()
{
var uname = document.contactform.name;
var uemail = document.contactform.email;
var uphone = document.contactform.phone;
var ucomment = document.contactform.comment;
{
if(allLetter(uname))
{
if(ValidateEmail(uemail))
{
if(alphanumeric(uphone))
{
return false;
function validate(uname)
{
if (uname.value.length == 0)
{
alert("Name should not be empty);
return false;
}
return true;
}
function validate(uphone)
{
var uphone_len = uphone.value.length;
if (uphone_len == 0 || uphone_len=="" )
{
alert("Phone should not be empty);
uphone.focus();
return false;
}
return true;
}
function Validate(uemail)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(uemail.value.match(mailformat))
{
return true;
}
else
{
alert("You have entered an invalid email address!");
uemail.focus();
return false;
}
function validate(ucomment)
{
var ucomment_len = ucomment.value.length;
if (ucomment_len == 0 || ucomment_len=="" )
{
alert("Comment should not be empty);
ucomment.focus();
return false;
}
return true;
}
}
I just cant work out exactly where I am going wrong here. What am I missing?