我的模式匹配表达式是这样我想检查并返回错误消息。
public function checkthe($str)
{
if(preg_match('/^\(?[+]?[0-9]{3,4}[-. ]?[0-9]{8,10}$/', $str)==TRUE)
{
return true;
}
else
{
$this->form_validation->set_message('checkthe', 'The %s should be in format XXX-XXXXXXXX');
return false;
}
}
答案 0 :(得分:0)
如果字符串
中没有+ /和0-9,我需要显示错误
如果确实如此,那么你的正则表达式应该是:
public function checkthe($str) {
return preg_match('~^[+/0-9]+$~', $str);
}
虽然包含样本输入总是更好。