$this->form_validation->set_rules('ttime','Time', 'required|regex_match[/^(0?[1-9]|1[012])(:[0-5]\d)$/]');
我的正则表达式仍然正确,但它显示错误为 严重性:警告
消息:preg_match():找不到结束分隔符“/”
文件名:libraries/Form_validation.php
行号:911
最佳答案
也遇到这个问题了。问题确实是 codeigniter 使用的管道 |
字符,但是添加单引号并不适合我。尝试:
1) 传递规则数组而不是管道字符串:
$this->form_validation->set_rules('field',
'field name',
array('required','regex_match[/your-regex/]'))
2) 创建自定义回调以与您指出的规则一起使用 here :
function my_func ($field) {
return (bool)preg_match('/your-regex-here/', $field);
}
$this->form_validation->set_rules('field','Field Name', 'required|my_func');
3) 您还可以使用由 1 和 2 组合而成的匿名函数
查看 documentation ,我希望这会有所帮助。
关于regex - preg_match() : No ending delimiter '/' found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26859773/