function testPostcode (pcode) { test = pcode size = test.length //test = test.toUpperCase(); //Change to uppercase // Strip leading spaces while (test.slice(0,1) == " ") { test = test.substr(1,size-1);size = test.length } // Strip trailing spaces while(test.slice(size-1,size)== " ") { test = test.substr(0,size-1);size = test.length } // Code length rule if (size < 6 || size > 8) { alert(test + " is not a valid postcode - wrong length"); return false } // leftmost character must be alpha character rule if (!(isNaN(test.charAt(0)))) { alert(test + " is not a valid postcode - cannot start with a number"); return false } // first character of inward code must be numeric rule if (isNaN(test.charAt(size-3))) { alert(test + " is not a valid postcode - alpha character in wrong position"); return false } // second character of inward code must be alpha rule if (!(isNaN(test.charAt(size-2)))) { alert(test + " is not a valid postcode - number in wrong position"); return false } // third character of inward code must be alpha rule if (!(isNaN(test.charAt(size-1)))) { alert(test + " is not a valid postcode - number in wrong position"); return false } // space in position length-3 rule if (!(test.charAt(size-4) == " ")) { alert(test + " is not a valid postcode - no space or space in wrong position"); return false } // only one space rule count1 = test.indexOf(" ");count2 = test.lastIndexOf(" "); if (count1 != count2) { alert(test + " is not a valid postcode - only one space allowed"); return false } return true }