function ValidPostCode(objPostCode,blankmsg){ //check postcode format is valid
  valPostCode = objPostCode.value
  valPostCode = valPostCode.toUpperCase(); //Change to uppercase
  size = valPostCode.length
  while (valPostCode.slice(0,1) == " ") //Strip leading spaces
  {valPostCode = valPostCode.substr(1,size-1);size = valPostCode.length}
  while(valPostCode.slice(size-1,size)== " ") //Strip trailing spaces
  {valPostCode = valPostCode.substr(0,size-1);size = valPostCode.length}
  while (valPostCode.indexOf('  ') !=-1) //Strip middle spaces
  {iIndex = valPostCode.indexOf('  ');valPostCode = valPostCode.substr(0,iIndex) + valPostCode.substr(iIndex + 1,size - iIndex)}
  if(valPostCode.indexOf(' ')==-1){//No Space
  valPostCode = valPostCode.substr(0,size-3) + ' ' + valPostCode.substr(size-3,3);}
  objPostCode.value = valPostCode; //write back to form field
  size = valPostCode.length
  if (size < 6 || size > 8){ //Code length rule
    if (size == 0){
      if (blankmsg.length>0){alert(blankmsg)}
      }else{
      alert(valPostCode + " is not a valid postcode - wrong length");
      }objPostCode.focus();return false;
    }
    if (!(isNaN(valPostCode.charAt(0)))){ //leftmost character must be alpha character rule
     alert(valPostCode + " is not a valid postcode - cannot start with a number");
     objPostCode.focus(); return false;
    }
    if (isNaN(valPostCode.charAt(size-3))){ //first character of inward code must be numeric rule
     alert(valPostCode + " is not a valid postcode - alpha character in wrong position (" + valPostCode.charAt(size-3) + ")");
     objPostCode.focus(); return false;
    }
    if (!(isNaN(valPostCode.charAt(size-2)))){ //second character of inward code must be alpha rule
     alert(valPostCode + " is not a valid postcode - number in wrong position");
     objPostCode.focus(); return false;
    }
    if (!(isNaN(valPostCode.charAt(size-1)))){ //third character of inward code must be alpha rule
     alert(valPostCode + " is not a valid postcode - number in wrong position");
     objPostCode.focus(); return false;
    }
    if (!(valPostCode.charAt(size-4) == " ")){//space in position length-3 rule
     alert(valPostCode + " is not a valid postcode - no space or space in wrong position");
     objPostCode.focus(); return false;
   }
   count1 = valPostCode.indexOf(" ");count2 = valPostCode.lastIndexOf(" ");
   if (count1 != count2){//only one space rule
     alert(valPostCode + " is not a valid postcode - only one space allowed");
     objPostCode.focus(); return false;
  }
  return true;
}