Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.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

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
Php Codeigniter验证规则帮助_Php_Codeigniter_Validation - Fatal编程技术网

Php Codeigniter验证规则帮助

Php Codeigniter验证规则帮助,php,codeigniter,validation,Php,Codeigniter,Validation,我想验证CI应用程序中的landphone和mobile phone字段。我已将验证规则设置为整数,但用户无法输入以“-”分隔的值。如果我使用“文本”类型,用户也可以输入字母……我如何解决这个问题……我希望用户在字段中输入“-”和“+”值,而不是任何其他文本 代码: 开箱即用,我认为没有任何东西可以做到这一点。您可能需要使用回调函数并使用一些正则表达式进行检查。我对正则表达式不是很流利,所以我不能准确地告诉你那里需要什么 您可以在CodeIgniter用户指南中找到有关回调的更多信息:您不能输入

我想验证CI应用程序中的landphone和mobile phone字段。我已将验证规则设置为整数,但用户无法输入以“-”分隔的值。如果我使用“文本”类型,用户也可以输入字母……我如何解决这个问题……我希望用户在字段中输入“-”和“+”值,而不是任何其他文本

代码:


开箱即用,我认为没有任何东西可以做到这一点。您可能需要使用回调函数并使用一些正则表达式进行检查。我对正则表达式不是很流利,所以我不能准确地告诉你那里需要什么


您可以在CodeIgniter用户指南中找到有关回调的更多信息:

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

您的验证规则:

$this->form_validation->set_rules('foo', 'Number', 'callback_number_validation');
//$str will be the value you want to verify
function number_validation($str) {
    return preg_match("your_regex", $str) ? true: false;
}
请注意如何使用关键字
callback\uuz
来标识要验证的函数

您的回调函数:

$this->form_validation->set_rules('foo', 'Number', 'callback_number_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('land_phone','land phone','trim | required | integer | minu length[1]| max_length[50]| xss_clean');$this->form_validation->set_rules('mobile_phone'、'mobile phone'、'trim | required | integer | min_length[1]| max_length[50]| xss_clean');我把你的代码粘贴到你的问题上了。将来,你应该编辑你的问题来添加任何额外的信息,而不是留下评论。好吧……但是我们如何解决这个问题呢