Skip to content

Instantly share code, notes, and snippets.

@jaikdean
Created February 7, 2012 11:24
Show Gist options
  • Save jaikdean/1759218 to your computer and use it in GitHub Desktop.
Save jaikdean/1759218 to your computer and use it in GitHub Desktop.
jQuery Ketchup validator for UK postcodes
$.ketchup.validation(
'ukpostcode',
'Please enter a valid UK postcode',
function(form, el, value){
var tidyValue = value.replace(/\s+/g, '');
var pattern = /^(GIR0AA)|((([A-PR-UWYZ][0-9][0-9]?)|(([A-PR-UWYZ][A-HK-Y][0-9][0-9]?)|(([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))))[0-9][ABD-HJLNP-UW-Z]{2})$/i;
return pattern.test(tidyValue);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment