【发布时间】:2014-05-01 01:16:42
【问题描述】:
我的 Laravel 规则和正则表达式操作有一个小问题:
基本上,规则就是这样的数组:
'room'=>'required|alpha_num|min:2|max:10',
我遇到的问题是使用正则表达式和 | (或)运算符,例如:
'cid'=>'required|regex:/^((comp)|(soen)|(engr)|(elec))\d{3}$/i',
我收到一个服务器错误提示:
ErrorException
preg_match(): No ending delimiter '/' found
我猜preg_match 会停在/.../ 内的第一个|。
有没有写上面的代码让它工作?
完整代码:
public static $rules = array(
'cid' => array('required', 'regex:/^((comp)|(soen)|(engr)|(elec))\d{3}$/i'),
'description'=>'required|regex:/^[A-Za-z \t]*$/i|min:3|unique:courses',
'credits'=>'required|regex:/^\d+(\.\d)?$/'
);
【问题讨论】: