-1
我用这个验证:验证英国短邮政编码
//validate postcode
function IsPostcode($postcode)
{
$postcode = strtoupper(str_replace(' ','',$postcode));
if(preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/",$postcode) || preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/",$postcode) || preg_match("/^GIR0[A-Z]{2}$/",$postcode))
{
return true;
}
else
{
return false;
}
}
但我希望能够验证像ME20和TN10邮政编码,而不是一个完全成熟的ME20 4RN,TN0 4RN的。
有人可以帮助我与正则表达式吗?
http://regular-expressions.info/tutorial.html – deceze
有一个库可以做到这一点https://gist.github.com/ChrisMcKee/4452116只需将incode选项设置为只验证第一部分 – Anigel
你对于正则表达式模式有多少了解?只有最基本的正则表达式知识才能从你已有的起点找出答案。我建议去读[更多关于正则表达式](http://www.regular-expressions.info/),而不是问这样一个基本问题。你会学到更多的东西。 – Spudley