Blade 上的空白验证 Laravel 5.2
White Spaces Validation on Blade Laravel 5.2
我正在创建一个像这样的:
{!! Form::text('name', null, [
'class' => 'form-control',
'placeholder'=>'Name',
"required" => "required|regex:/(^[A-Za-z0-9]+$)+/",
'maxlength' => 55,
'minlength' => 5
])
!!}
我想确保用户不能仅输入空白 space 五次以上。但是这个正则表达式:/(^[A-Za-z0-9]+$)+/ 不起作用。每次我输入 space 超过 5 次,它总是有效的。那么如何预防这件事...???
我已经尝试 'field'=> 'regex:/(^[A-Za-z0-9 ]+$)+/'
从这个 link : Laravel - Validate only letters, numbers and spaces using regex。它对我不起作用
终于找到答案了:
{!! Form::text('name', null, [
'class' => 'form-control',
'placeholder'=>'Name',
"required" => 'required',
'maxlength' => 55,
'minlength' => 5,
'pattern' => ".*\S+.*"
])
!!}
所以我只需要添加 'pattern' => ".*\S+.*"
然后空白 space/white space 将被视为无效输入。
我正在创建一个像这样的:
{!! Form::text('name', null, [
'class' => 'form-control',
'placeholder'=>'Name',
"required" => "required|regex:/(^[A-Za-z0-9]+$)+/",
'maxlength' => 55,
'minlength' => 5
])
!!}
我想确保用户不能仅输入空白 space 五次以上。但是这个正则表达式:/(^[A-Za-z0-9]+$)+/ 不起作用。每次我输入 space 超过 5 次,它总是有效的。那么如何预防这件事...???
我已经尝试 'field'=> 'regex:/(^[A-Za-z0-9 ]+$)+/'
从这个 link : Laravel - Validate only letters, numbers and spaces using regex。它对我不起作用
终于找到答案了:
{!! Form::text('name', null, [
'class' => 'form-control',
'placeholder'=>'Name',
"required" => 'required',
'maxlength' => 55,
'minlength' => 5,
'pattern' => ".*\S+.*"
])
!!}
所以我只需要添加 'pattern' => ".*\S+.*"
然后空白 space/white space 将被视为无效输入。