Skip to content

Instantly share code, notes, and snippets.

@benshimmin
Created January 29, 2013 10:03
Show Gist options
  • Save benshimmin/4663176 to your computer and use it in GitHub Desktop.
Save benshimmin/4663176 to your computer and use it in GitHub Desktop.
Simple (albeit slightly overly permissive) UK postcode regular expression
var regex = /^[A-Z]{1,2}[0-9]{1,2}[A-Z]? ?[0-9][A-Z]{2}$/i;
/**
* NB. This is case-insensitive and doesn't care about the whitespace.
*
* Matches these formats:
*
* AA9A 9AA
* A9A 9AA
* A9 9AA
* A99 9AA
* AA9 9AA
* AA99 9AA
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment