hi I need to accept uk post codes but this script i'm using only does us zip code is there any way i can change this? function validateZIP(field) { var valid = "0123456789-"; var hyphencount = 0; if (field.length!=5 && field.length!=10) { //alert("Please enter your 5 digit or 5 digit+4 zip code."); return true; } for (var i=0; i < field.length; i++) { temp = "" + field.substring(i, i+1); if (temp == "-") hyphencount++; if (valid.indexOf(temp) == "-1") { //alert("Invalid characters in your zip code. Please try again."); return true; } if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) { //alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'. Please try again."); return true; } PHP: any help please,this has been doing my head in thanks
You can use following code: function isUKUSPostCode(src) { Â if (validateZIP(src) == true) return true; Â return isUKPostCode(src);Â } Â Â function isUKPostCode(src) { Â if (src.length == 6 && isLetter(src[0]) && isDigit(src[1]) && src[2] == ' ' && isDigit(src[3]) && isLetter(src[4]) && isLetter(src[5])) return true; Â if (src.length == 7 && ((isLetter(src[0]) && isDigit(src[1]) && isDigit(src[2])) || (isLetter(src[0]) && isLetter(src[1]) && isDigit(src[2])) || (isLetter(src[0]) && isDigit(src[1]) && isLetter(src[2]))) && src[3] == ' ' && isDigit(src[4]) && isLetter(src[5]) && isLetter(src[6])) return true; Â if (src.length == 8 && isLetter(src[0]) && isLetter(src[1]) && isDigit(src[2]) && (isDigit(src[3]) || isLetter(src[3])) && src[4] == ' ' && isDigit(src[5]) && isLetter(src[6]) && isLetter(src[7])) return true; Â return false; } function isDigit(src) { Â return '0123456789'.indexOf(src) >= 0; } function isLetter(src) { Â return 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.indexOf(src) >= 0; } Code (markup): Â