<!-- Validate Address Form
function checkpostcodeform (postcode_form)
{
test = document.postcode_form.code_postcode.value; size = test.length
test = test.toUpperCase(); //Change to text to uppercase
count1 = test.indexOf(" ");
count2 = test.lastIndexOf(" ");
while (test.slice(0,1) == " ") //Strip any leading spaces
{
test = test.substr(1,size-1);size = test.length
}
while(test.slice(size-1,size)== " ") //Strip any trailing spaces
{
test = test.substr(0,size-1);size = test.length
}
document.postcode_form.code_postcode.value = test; //Write the modified postcode back in the form
if (postcode_form.code.value != "" )
{
if (postcode_form.code_postcode.value == "" )
{
alert( "Please enter your postcode" );
postcode_form.code_postcode.focus();
return false;
}
else if (size < 6 || size > 8)
{ //Check the length of the postcode
alert(test + " is not a valid postcode - it appears to be the wrong length");
postcode_form.code_postcode.focus();
return false;
}
else if (!(isNaN(test.charAt(0))))
{ //The start of the postcode must be a letter
alert(test + " is not a valid postcode - it should not start with a number");
postcode_form.code_postcode.focus();
return false;
}
else if (isNaN(test.charAt(size-3)))
{ //First character of inward code must be right
alert(test + " is not a valid postcode - alpha character in wrong position");
postcode_form.code_postcode.focus();
return false;
}
else if (!(isNaN(test.charAt(size-2))))
{ //Second character of inward code must be a number
alert(test + " is not a valid postcode - number in wrong position");
postcode_form.code_postcode.focus();
return false;
}
else if (!(isNaN(test.charAt(size-1))))
{ //Third character of inward code must be letter
alert(test + " is not a valid postcode - number in wrong position");
postcode_form.code_postcode.focus();
return false;
}
else if (!(test.charAt(size-4) == " "))
{//Check they have included a space
alert(test + " is not a valid postcode - no space or space in wrong position");
postcode_form.code_postcode.focus();
return false;
}
else if (count1 != count2)
{//Make sure they have only put in one space
alert(test + " is not a valid postcode - only one space allowed");
postcode_form.code_postcode.focus();
return false;
}
}
else
{
return true;
}
}
//-->
