Want to validate html form with one javascript function. I have the form validation, thats only validating, if the field is empty or not. I want to check if the email is correct and the phone number is numeric. Right now the form open popup alert but after entering email it stops.
Here are my form codes
<form name="appointment" method="post" onsubmit="return doValidate();">
Name:*<br />
<input type="text" name="requiredname" />
Email:*<br />
<input type="text" name="requiredemail" />
Phone:*<br />
<input type="text" name="requiredphone" />
Appointment Date:*<br />
<input type="text" name="requireddate" />
Appointment Time:*<br />
<input type="text" name="requiredtime" /><br /><br />
<input name="submit" type="submit" value="Book Now" /> </form>
This is the Javascript codes:-
function doValidate()
{
if (document.appointment.requiredname.value =="")
{
alert("Please put your name");
document.appointment.requiredname.focus();
return false;
}
var readmail = document.appointment.requiredemail;
var checkatsymbol = readmail.indexof("@");
var checkdotsymbol = readmail.lastindexof(".");
if (readmail.value =="" || checkatsymbol<1)
{
alert("Please put the correct email address");
document.appointment.requiredemail.focus();
return false;
}
if (document.appointment.requiredphone.value =="" )
{
alert("Please put your phone");
document.appointment.requiredphone.focus();
return false;
}
if (document.appointment.requireddate.value =="" )
{
alert("Please put your appointment date as DD/MM/YYYY");
document.appointment.requireddate.focus();
return false;
}
if (document.appointment.requiredtime.value =="")
{
alert("Please put your appointment time as HH:MM AM/PM");
document.appointment.requiredtime.focus();
return false;
}
return ( true );
}