Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter 验证包含'+';和'-';人物_Codeigniter - Fatal编程技术网

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)