Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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 代码点火器正则表达式匹配时间不工作_Php_Regex_Codeigniter - Fatal编程技术网

Php 代码点火器正则表达式匹配时间不工作

Php 代码点火器正则表达式匹配时间不工作,php,regex,codeigniter,Php,Regex,Codeigniter,我试图使用这个正则表达式([01]?[0-9]| 2[0-3]):00:00将24小时格式与00分和00秒匹配 在codeigniter的表单验证规则中,我输入了正则表达式 regex_match[([01]?[0-9]|2[0-3]):00:00] 然后继续 Message: preg_match() [function.preg-match]: No ending matching delimiter ‘)’ found 正则表达式在php中工作,但不通过CI正则表达式规则。我做错了什

我试图使用这个正则表达式
([01]?[0-9]| 2[0-3]):00:00
将24小时格式与00分和00秒匹配

在codeigniter的表单验证规则中,我输入了正则表达式

regex_match[([01]?[0-9]|2[0-3]):00:00] 
然后继续

Message: preg_match() [function.preg-match]: No ending matching delimiter ‘)’ found

正则表达式在php中工作,但不通过CI正则表达式规则。我做错了什么-/

您可以使用回调,而不是使用正则表达式匹配器

比如:

$this->form_validation->set_rules('number', 'Number', 'callback_validate_24hourtimestamp');

function validate_24hourtimestamp ($num)
{
    return preg_match('/^([01]?[0-9]|2[0-3]):00:00$/', $num);
}

您可以使用回调,而不是使用正则表达式匹配器

比如:

$this->form_validation->set_rules('number', 'Number', 'callback_validate_24hourtimestamp');

function validate_24hourtimestamp ($num)
{
    return preg_match('/^([01]?[0-9]|2[0-3]):00:00$/', $num);
}

或者它可能需要一个分隔符:
regex_match[/([01]?[0-9]| 2[0-3]):00:00/]
-我不确定,我找不到该规则的任何文档。我可能是错的,但我记得在表单验证中读到一些关于regex_模式的内容,这些内容不允许使用方括号或字符类。第一个类的第一个结束括号将结束匹配,从而给出分隔符错误。yes CI不支持此类正则表达式:(最好的解决方案是回调?或者它可能需要分隔符:
regex_match[/([01]?[0-9]| 2[0-3]):00:00/]
-我不确定,我找不到该规则的任何文档。我可能是错的,但我记得在表单验证中阅读了一些关于regex_模式的内容,这些内容不允许使用方括号或字符类。第一个类的第一个右括号将结束匹配,从而给出分隔符错误。是的CI不支持这种类型的of regex:(最好的解决办法是回电话谢谢,这就是我最后做的事谢谢,这就是我最后做的事