且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CodeIgniter中的regex_match form_validation生成:消息:preg_match():未找到结束定界符'/'

更新时间:2022-04-21 22:35:02

设置验证规则时, |所以在你的正则表达式中的|是导致验证规则分裂在那些,这是导致错误。请在此处讨论此问题。它似乎是一个限制或错误codeigniter。你可以通过运行一个有和没有|的正则表达式来检查它,看看管道的使用是否会导致错误。如果是这种情况,那么您可能必须通过其他方式regex验证,也许使用回调函数详细 page ,你的函数将使用regex来执行preg_match,当然需要在函数里面,然后返回true / false。

When you set the validation rules you separate them with a | so the |'s in your regex is causing the validation rule to split at those and that is causing the error. Discussion here on the issue. It seems it's a limitation or bug in codeigniter. You can test it out by running a regex with and without |'s and see if the usage of pipes will cause an error. If that is the case then you may have to validate by regex by other means, maybe use a callback function as detailed on this page where your function will do a preg_match using the regex which needs to be inside the function of course and then return true/false.