php laravel 正则表达式验证不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22430529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:55:50  来源:igfitidea点击:

laravel regex validation not working

phpregexformsvalidationlaravel

提问by Scott

I've just started using laravel and I'm working on validating a textarea in one of my forms.

我刚刚开始使用 laravel,我正在验证我的一种表单中的 textarea。

The textarea is for the users bio and so I only want to allow letters, numbers, spaces and the following characters: , . ? ; : ' " - () ! / @ $

textarea 是供用户 bio 使用的,所以我只想允许字母、数字、空格和以下字符: , . ? ; : '" - () ! / @ $

This is what I have

这就是我所拥有的

$validator = Validator::make(Input::all(),
array('bio' => array('regex:[a-zA-Z0-9 ,\.\?;:\'"-\(\)!/@$]')
    )
);

I've been searching and trying a lot to get it to work but I just can't figure it out.

我一直在寻找并尝试很多让它工作,但我就是无法弄清楚。

Any help would be much appreciated.

任何帮助将非常感激。

Thanks

谢谢

回答by enga

Try this:

尝试这个:

array('Regex:/^[A-Za-z0-9\-! ,\'\"\/@\.:\(\)]+$/')