Codeigniter 验证包含'+';和'-';人物

Codeigniter 验证包含'+';和'-';人物,codeigniter,Codeigniter,在CodeIgniter中,如何验证包含“+”和“-”符号的电话号码?您不能输入带“-”的号码,因为您将整数定义为验证规则。因此,验证将失败。您需要使用正则表达式,以便创建更复杂的验证。有关详细信息,请参阅中有关验证的主题 您的验证规则: $this->form_validation->set_rules('foo', 'Number', 'callback_number_validation'); Note how the keyword callback_ is used to

在CodeIgniter中,如何验证包含“+”和“-”符号的电话号码?

您不能输入带“-”的号码,因为您将整数定义为验证规则。因此,验证将失败。您需要使用正则表达式,以便创建更复杂的验证。有关详细信息,请参阅中有关验证的主题

您的验证规则:

$this->form_validation->set_rules('foo', 'Number', 'callback_number_validation');
Note how the keyword callback_ is used to identify CI your function for validation.
您的回调函数:

//$str will be the value you want to verify
function number_validation($str) {
    return preg_match("your_regex", $str) ? true: false;
}

不能输入带“-”的数字,因为您已将整数定义为验证规则。因此,验证将失败。您需要使用正则表达式,以便创建更复杂的验证。有关详细信息,请参阅中有关验证的主题

您的验证规则:

$this->form_validation->set_rules('foo', 'Number', 'callback_number_validation');
Note how the keyword callback_ is used to identify CI your function for validation.
您的回调函数:

//$str will be the value you want to verify
function number_validation($str) {
    return preg_match("your_regex", $str) ? true: false;
}

不需要三元。只需
返回preg\u match(“your\u regex”,$str)不需要三元。只需
返回preg\u match(“your\u regex”,$str)