I\'m using this validator:
//validate postcode
function IsPostcode($postcode)
{
$postcode = strtoupper(str_replace(\' \',\'\',$postcode));
if(preg_match(
you can use my updated regex to solve you problem
it working from my end to validate UK zip code
<?php
function IsPostcode($postcode)
{
$postcode = strtoupper(str_replace(' ','',$postcode));
if(preg_match("/(^[A-Z]{1,2}[0-9R][0-9A-Z]?[\s]?[0-9][ABD-HJLNP-UW-Z]{2}$)/i",$postcode) || preg_match("/(^[A-Z]{1,2}[0-9R][0-9A-Z]$)/i",$postcode))
{
return true;
}
else
{
return false;
}
}
echo $result = IsPostcode('ME20');
?>
OUTPUT
1
Hope this will sure help you.