這些值的格式爲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