Skip to content

Instantly share code, notes, and snippets.

@simonbowen
Created April 20, 2011 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonbowen/931311 to your computer and use it in GitHub Desktop.
Save simonbowen/931311 to your computer and use it in GitHub Desktop.
Stupid Postcode Regex
$postcode = 'IP13SU';
$pattern = "/^(GIR 0AA)|((([A-Z-[QVX]][0-9][0-9]?)|(([A-Z-[QVX]][A-Z-[IJZ]][0-9][0-9]?)|(([A-Z-[QVX]][0-9][A-HJKSTUW])|([A-Z-[QVX]][A-Z-[IJZ]][0-9][ABEHMNPRVWXY]))))[0-9][A-Z-[CIKMOV]]{2})$/";
return (boolean) preg_match($pattern, $postcode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment