I am trying to validate UK and overseas postcode. The UK postcode validation is working but not the overseas. Is there any specific regex for the overseas or can be done with the regex I have used in the jsfiddle code.
I have gone through this post - https://stackoverflow.com/a/164994/2455424 and tried to use the following regex but didn't work.
^(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) ?[0-9][ABD-HJLNP-UW-Z]{2})$
So I have commented out that line.
Jquery code -
$('#testForm').on('submit', function() {
var zip = $('#zip').val();
zip = zip.replace(/\s/g, "");
var regex = /[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}/gi;
//var regex = ^(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) ?[0-9][ABD-HJLNP-UW-Z]{2})$;
var resultzip = regex.test(zip);
if (false === resultzip) {
alert('The postcode is not valid.');
return false;
}
});
Demo -- https://jsfiddle.net/squidraj/q4ouLns7/5/
Any help is highly appreciated.