i have written a javascript code for mobile number and state validation but function is working except mobile number and state validation , where is my mistakes ?
<%@ page language="java" contentType="te xt/html; charset=ISO-8859-1"
pageEncoding="I SO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function checkForm(form)
{
if(form.email1. value != "" && form.email1.val ue == form.email2.val ue)
{
}
else
{ alert("Error: Please check that you've entered and confirmed your email id!");
form.email1.foc us();
return false;
}
if(form.pwd1.va lue != "" && form.pwd1.value == form.pwd2.value )
{
if(form.pwd1.va lue.length < 6)
{
alert("Error: Password must contain at least one characters!");
form.pwd1.focus ();
return false;
}
if(form.pwd1.va lue == form.email.valu e) {
alert("Error: Password must be different from Username!");
form.pwd1.focus ();
return false;
}
re = /[0-9]/;
if(!re.test(for m.pwd1.value))
{
alert("Error: password must contain at least one number (0-9)!");
form.pwd1.focus ();
return false;
}
re = /[a-z]/;
if(!re.test(for m.pwd1.value))
{
alert("Error: password must contain at least one lowercase letter (a-z)!");
form.pwd1.focus ();
return false;
}
}
else {
alert("Error: Please check that you've entered and confirmed your password!");
form.pwd1.focus ();
return false;
}
if(form.mnum1.v alue != "" && form.mnum1.valu e == form.mnum2.valu e)
{
}
else
{ alert("Error: Please check that you've entered and confirmed your mobile number!");
form.mnum1.focu s();
return false;
}
if(document.for m.Country.selec tedIndex=="")
{
alert ( "Please select a state!");
return false;
}
return true;
}
</script>
</head>
<body >
<form name = "form" action="./careers2.jsp" method="post" onsubmit = "return checkForm(this) ;">
<center><br><br >
<h2>First step Registration start</h2>
<br>
<center>
<table border="2">
<tr><td align="right">E-mail :</td> <td align="left"><i nput type="email" name="email1" required></td> </tr>
<tr><td align="right">R etype E-mail :</td> <td align="left"><i nput type="email" name="email2" required></td> </tr>
<tr><td align="right">P assword :</td> <td align="left"><i nput type = "password" name = "pwd1" required></td></tr>
<tr><td align="right">R etype Password : </td><td align="left"><i nput type = "password" name = "pwd2" required></td></tr>
<!-- <tr><td align="right">M obile Number : </td><td align="left"><i nput type = "tel" name = "mnum1" required></td></tr>
<tr><td align="right">R etype Mobile Number : </td><td align="left"><i nput type = "tel" name = "mnum2" required></td></tr>-->
<%
out.write("<tr> <td align=\"right\" >State :</td><td align=\"left\"> <select name=\"Country\ " >"+
"<option value=\"Select\ ">----------Select State------------</option>"+
"<option value=\"Andaman and Nicobar Islands\">Andam an and Nicobar Islands</option>"+
"<option value=\"Andhra Pradesh\">Andhr a Pradesh</option>"+
"<option value=\"Arunach al Pradesh\">Aruna chal Pradesh</option>"+
"<option value=\"Assam\" >Assam</option>"+
"<option value=\"Bihar\" >Bihar</option>"+
"</select> </td></tr>"
);
%>
</table><br><br>
<input type = "submit" value = "Submit" class="button1" ></center>
</center><br><br> <br><br><br><br ><br><br><br><b r><br>
</form>
</body>
</html>
<%@ page language="java" contentType="te xt/html; charset=ISO-8859-1"
pageEncoding="I SO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function checkForm(form)
{
if(form.email1. value != "" && form.email1.val ue == form.email2.val ue)
{
}
else
{ alert("Error: Please check that you've entered and confirmed your email id!");
form.email1.foc us();
return false;
}
if(form.pwd1.va lue != "" && form.pwd1.value == form.pwd2.value )
{
if(form.pwd1.va lue.length < 6)
{
alert("Error: Password must contain at least one characters!");
form.pwd1.focus ();
return false;
}
if(form.pwd1.va lue == form.email.valu e) {
alert("Error: Password must be different from Username!");
form.pwd1.focus ();
return false;
}
re = /[0-9]/;
if(!re.test(for m.pwd1.value))
{
alert("Error: password must contain at least one number (0-9)!");
form.pwd1.focus ();
return false;
}
re = /[a-z]/;
if(!re.test(for m.pwd1.value))
{
alert("Error: password must contain at least one lowercase letter (a-z)!");
form.pwd1.focus ();
return false;
}
}
else {
alert("Error: Please check that you've entered and confirmed your password!");
form.pwd1.focus ();
return false;
}
if(form.mnum1.v alue != "" && form.mnum1.valu e == form.mnum2.valu e)
{
}
else
{ alert("Error: Please check that you've entered and confirmed your mobile number!");
form.mnum1.focu s();
return false;
}
if(document.for m.Country.selec tedIndex=="")
{
alert ( "Please select a state!");
return false;
}
return true;
}
</script>
</head>
<body >
<form name = "form" action="./careers2.jsp" method="post" onsubmit = "return checkForm(this) ;">
<center><br><br >
<h2>First step Registration start</h2>
<br>
<center>
<table border="2">
<tr><td align="right">E-mail :</td> <td align="left"><i nput type="email" name="email1" required></td> </tr>
<tr><td align="right">R etype E-mail :</td> <td align="left"><i nput type="email" name="email2" required></td> </tr>
<tr><td align="right">P assword :</td> <td align="left"><i nput type = "password" name = "pwd1" required></td></tr>
<tr><td align="right">R etype Password : </td><td align="left"><i nput type = "password" name = "pwd2" required></td></tr>
<!-- <tr><td align="right">M obile Number : </td><td align="left"><i nput type = "tel" name = "mnum1" required></td></tr>
<tr><td align="right">R etype Mobile Number : </td><td align="left"><i nput type = "tel" name = "mnum2" required></td></tr>-->
<%
out.write("<tr> <td align=\"right\" >State :</td><td align=\"left\"> <select name=\"Country\ " >"+
"<option value=\"Select\ ">----------Select State------------</option>"+
"<option value=\"Andaman and Nicobar Islands\">Andam an and Nicobar Islands</option>"+
"<option value=\"Andhra Pradesh\">Andhr a Pradesh</option>"+
"<option value=\"Arunach al Pradesh\">Aruna chal Pradesh</option>"+
"<option value=\"Assam\" >Assam</option>"+
"<option value=\"Bihar\" >Bihar</option>"+
"</select> </td></tr>"
);
%>
</table><br><br>
<input type = "submit" value = "Submit" class="button1" ></center>
</center><br><br> <br><br><br><br ><br><br><br><b r><br>
</form>
</body>
</html>
Comment