I was looking for a valid UK postcode regex pattern, but seems that any of them work as a traditional or normal regex.
I test all patterns using this tool: https://regex101.com/
The regex I found in this document https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/413338/Bulk_Data_Transfer_-_additional_validation_valid_from_March_2015.pdf is not working.
I tried all regex in this wiki page https://en.wikipedia.org/wiki/Talk:Postcodes_in_the_United_Kingdom but nothing.
Am I doing something wrong?
I'm writing an Angular directive.
var regex = ????;
// add a parser that will process each time the value is
// parsed into the model when the user updates it.
ngModel.$parsers.unshift(function(value) {
// test and set the validity after update.
var valid = regex.test(value);
console.log(valid);
ngModel.$setValidity('ukPostcode', valid);
// if it's valid, return the value to the model,
// otherwise return undefined.
return valid ? value : undefined;
});
Thank you.