这些值的格式为123-123-123-12345,我希望preg_match能够工作。你能看到这个regEx有什么问题吗?PHP preg_match - 此RegEx有什么问题?
foreach($elem as $key=>$value) {
// Have tried this With and without the + before the $ as well
if(preg_match("/^[0-9]{3}\-[0-9]{3}\-[0-9]{3}\-[0-9]{5}+$/", $value)) {
echo "Yeah match Elm: ".$value."<br />";
} else {
echo "Boo Hoo Elm: '".$value."'<br />";
}
}
也试过
/^\d{3}\-\d{3}\-\d{3}\-\d{5}+$/
//With and without the + before the $
他们都失败,嘘呼;(
编辑:
var_dump($elem)
array(3) { [0]=> string(1) "c" [1]=> string(0) "" [2]=> string(36) "123-123-123-12345" }
在这种情况下,您不需要转义破折号。 – Gumbo 2009-09-25 19:31:16
** + **似乎没有做任何事情,它可以在没有它的情况下工作,并且在最后以10位数字失败。 – jeroen 2009-09-25 20:04:45
顺便说一句,你的数据有些奇怪,我只计算17个字符,为什么要给一个字符串(36)? – jeroen 2009-09-25 20:07:46