Hi guys,
I have a problem, can someone help me? I'm not sure why but none of my validation functions are working!!!!
I have a problem, can someone help me? I'm not sure why but none of my validation functions are working!!!!
Code:
<html>
<head><title>Registration Details</title>
<SCRIPT LANGUAGE="JavaScript">
function processForm1() {
form1 = document.forms["formOne"]
if (form1.firstname.value==""){
alert("you must fill in your first name")
formOne.firstname.focus();
}
else if (form1.lastname.value==""){
alert("you must fill in your lastname")
formOne.lastname.focus();
}
else if (form1.postcode.value==""){
alert("you must fill in your postcode")
formOne.postcode.focus();
}
else if (form1.dateofbirth.value==""){
alert("you must fill in your DOB")
formOne.dateofbirth.focus();
}
else {
controlForm = parent.frames[1].document.controlForm
controlForm.firstname.value=form1.firstname.value
controlForm.lastname.value=form1.lastname.value
controlForm.Address.value=form1.Address.value
controlForm.city.value=form1.city.value
controlForm.postcode.value=form1.postcode.value
controlForm.dateofbirth.value=form1.dateofbirth.value
controlForm.contactphonenumber.value=form1.contactphonenumber.value
controlForm.emailaddress.value=form1.emailaddress.value
controlForm.mypassword.value=form1.mypassword.value
}
}
function PhoneNumber{
if (form1.checkphonenumber.value==""){
alert("you must fill in your contactphonenumber")
formOne.checkphonenumber.focus();
}
var stripped = checkphonenumber.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
else if (isNaN(parseInt(stripped))) {
alert("the phone number contains illegal characters")}
else if (!(stripped.length == 11)) {
alert("The phone number is the wrong length. Make sure you included an area code.")}
}
function checkEmail{
var emailFilter=/^.+@.+\..{2,3,4,6}$/;
if (form1.emailaddress.value==""){
alert("you must fill in your email address")
formOne.emailaddress.focus();
}
else if (!(emailFilter.test(emailaddress))) {
alert("Enter a valid email add")
}
else if (form1.mypassword.value==""){
alert("you must fill in your password")
formOne.mypassword.focus();}
}
function checkPassword{
var illegalChars = /\W/;
if ((mypassword.length < 6) || (mypassword.length > 8)) {
alert("Password should have atleast 6 characters but no more than 7.")
formOne.mypassword.focus();
}
else if (illegalChars.test(mypassword)) {
alert("The password can only contain letters and numbers")}
}
</script>
</head>
<body>
<form method="GET" action="http://localhost:8081/MyServlet" NAME="formOne" >
<center>
<h1>Registration Details</h1>
<br><br>
First Name <input type="text" name="firstname" value=""><br><br>
Last Name <input type="text" name="lastname" value=""><br><br>
Address <input type="text" name="address" value=""><br><br>
City <input type="text" name="city" value=""><br><br>
County (optional) <input type="text" name="county" value=""><br><br>
Post Code <input type="text" name="postcode" value=""><br><br>
Country <input type="text" name="country" value=""><br><br>
Contact Phone Number <input type="text" name="contactphonenumber" value=""><br><br>
Date of Birth <input type="text" name="dateofbirth" value=""><br><br>
Email Address <input type="text" name="emailaddress" value=""><br><br>
Password (minimum 6 characters) <INPUT TYPE=PASSWORD NAME="mypassword"><br><br>
<input type="BUTTON" NAME="Submit" value="--SUBMIT--" onClick="processForm1()">
</center>
</form>
</body>
</html>
Comment