Hello i'm doing javascript validation on my form and I don't know how to do phone number validation so it only has numbers and single spaces allowed and also credit card validation which I want it to display between 13 and 18 numbers and single spaces.
Javascript:
HTML/PHP:
Can anyone please help me out with this? Thankyou.
Javascript:
Code:
<script type="text/javascript">
function validateForm()
{
var x=document.forms["checkout_details"]["firstname"].value;
if (x==null || x=="")
{
alert("Please fill out your First Name");
return false;
}
var x=document.forms["checkout_details"]["lastname"].value;
if (x==null || x=="")
{
alert("Please fill out your Last Name");
return false;
}
var x=document.forms["checkout_details"]["address"].value;
if (x==null || x=="")
{
alert("Please fill out your Address");
return false;
}
var x=document.forms["checkout_details"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert("Your Email Address is not valid. Please fill out a valid Email Address");
return false;
}
}
</script>
Code:
echo'<form name="checkout_details" action="confirm.php" onsubmit="return validateForm()" method="post">';
echo'<font color="red">*</font> <b>First Name:</b> <input type="text" name="firstname"><br /><br />';
echo'<font color="red">*</font> <b>Last Name:</b> <input type="text" name="lastname"><br /><br />';
echo'<font color="red">*</font> <b>Address:</b> <textarea name="address" rows="4" cols="20"></textarea><br /><br />';
echo'<font color="red">*</font> <b>Email Address:</b> <input type="text" name="email"><br /><br />';
echo'<font color="red">*</font> <b>Phone Number:</b> <input type="text" name="phone"><br /><br />';
echo'<font color="red">*</font> <b>Delivery Method:</b><br />';
echo'<input type="radio" name="radio" id="regularpost" checked="true">Regular Post<br />';
echo'<input type="radio" name="radio" id="courier">Courier<br />';
echo'<input type="radio" name="radio" id="expresscourier">Express Courier<br /><br />';
echo'<font color="red">*</font> <b>Please sign me up for the newsletter:</b> <input type="checkbox" name="checkbox"><br /><br />';
echo'<input type="submit" value="Purchase">';
echo'</form>';