朱纯树博客
VPS测评推荐网站
cloudacead cloudacead

TP5验证器填写正则表达式报错preg_match: No ending delimiter ‘/’ found解决办法

错误写法:

$validate = new Validate([
	'password|密码' => '/(^$)|(.+){6,16}$/',
	'repass|确认密码' => '/(^$)|(.+){6,16}$/',
	'tel|手机号' => 'require|/^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/'
]);

以前一直都是这么写的, 这次就报错了…不知道为啥

正确写法:

$param = request()->post();

$validate = new Validate([
	'password|密码' => ['regex:/(^$)|(.+){6,16}$/'],
	'repass|确认密码' => ['regex:/(^$)|(.+){6,16}$/'],
	'tel|手机号' => ['require','regex:/^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/']
]);

if (!$validate->check($param)) {
	return json(['code' => 0, 'msg' => $validate->getError()]);
}

记录一下.
-End-

文章来源于互联网:TP5验证器填写正则表达式报错preg_match: No ending delimiter ‘/’ found解决办法

赞(0) 打赏
未经允许不得转载:VPS测评推荐网站 - 朱纯树博客 » TP5验证器填写正则表达式报错preg_match: No ending delimiter ‘/’ found解决办法

评论 34

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #45

    Hey! I’m at work browsing your blog from my new iphone 4!
    Just wanted to say I love reading your blog and look forward to all your posts!
    Carry on the great work!

    My web-site: tracfone 2022

    tracfone 20221周前 (11-26)回复
  2. #44

    I’m not sure the place you’re getting your info, however good topic.
    I needs to spend some time studying more or understanding more.

    Thank you for excellent info I was searching for this information for my mission.

    tinyurl.com3个月前 (09-10)回复
  3. #43

    You can definitely see your skills within the work you write.
    The world hopes for even more passionate writers like you who aren’t
    afraid to mention how they believe. All the time follow your heart.

    http://tinyurl.com/3个月前 (09-09)回复
  4. #42

    There is certainly a great deal to find out about this issue.
    I like all the points you made.

    http://tinyurl.com/3个月前 (09-05)回复