I am very new to javascript and I need help to get the postcode validation of this script right.
Its supposed to check that the postcode contains four characters, but it returns the "four numbers alert" when any number of characters are entered.
What is the correct expression to produce the alert when the postcode does not contain four characters?
function Blank_TextField_Validator(form)
{
if (form.Name.value == "")
{
alert("Please fill in the Name field");
form.Name.focus();
return (false);
}
if (form.Address.value == "")
{
alert("Please fill in the Address field");
form.Address.focus();
return (false);
}
if (form.Suburb.value == "")
{
alert("Please fill in the Suburb field");
form.Suburb.focus();
return (false);
}
if (form.Postcode.value == "")
{
alert("Please fill in the Postcode field");
form.Postcode.focus();
return (false);
}
if (form.Postcode.length !=4)
{
alert("Your Postcode must contain four numbers.");
form.Postcode.focus();
return (false);
}
if (form.Email.value == "")
{
alert("Please enter a valid Email");
form.Email.focus();
return (false);
}
if (form.Email.value.indexOf("@", 0) < 0)
{
alert("Please enter a valid Email");
form.Email.focus();
return (false);
}
if (form.Email.value.indexOf(".", 0) < 0)
{
alert("Please enter a valid Email");
form.Email.focus();
return (false);
}
if (form.OrderText.value == "")
{
alert("Please enter your order");
form.OrderText.focus();
return (false);
}
if (form.Type.value == "")
{
alert("Please fill in the Type field");
form.Type.focus();
return (false);
}
if (form.ExpiryMonth.value == "")
{
alert("Please fill in the Expiry Month");
form.ExpiryMonth.focus();
return (false);
}
if (form.ExpiryYear.value == "")
{
alert("Please fill in the Expiry Year");
form.ExpiryYear.focus();
return (false);
}
return (true);
}