這是我笨功能:preg_replace不工作!
function edit_phone($phone)
{
if (preg_match('/^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/', $phone))
{
return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1-$2-$3", $phone);
}
else
{
$this->CI->validation->set_message('phone', "This must be a 10-digit USA phone number.");
return FALSE;
}
}
這證實/好嗎檢查輸入,但在db不重新格式化。
驗證非常好!但爲什麼這不會返回一個標準的電話號碼?!
也許你不保存edit_phone的返回值? – 2009-12-26 22:57:08
啊,你可能是對的!你能舉個例子嗎?我是新來的...... – 2009-12-26 23:04:29