力图让无论是英国邮政编码(GF433ED)或欧洲邮政编码(12345)返回true或false,但下面的代码始终返回false:正则表达式jQuery的邮政编码为欧洲或英国
function valid_postcode(postcode) {
postcode = postcode.replace(/\s/g, "");
alert(postcode);
var regex = /^[A-Z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}|^[0-9]{5}$/;
return regex.test(postcode);
}
任何帮助将不胜感激。
感谢
请注意您的英国邮政编码正则表达式不完整。在这里看到英国政府提供的:([Gg] [Ii] [Rr] 0 [Aa] {2})|((([A-Za-z] [0-9] {1,2 })|(([A-ZA-Z] [A-HA-HJ-YJ-Y] [0-9] {1,2})|(([A-ZA-Z] [0-9] [ A-ZA-Z])|?([A-ZA-Z] [A-HA-HJ-YJ-Y] [0-9] [A-ZA-Z]))))\ S [O- 9] [A-Za-z] {2})'https://stackoverflow.com/questions/164979/uk-postcode-regex-comprehensive –