Maryadi Poipo
Maryadi Poipo

Reputation: 1478

White Spaces Validation on Blade Laravel 5.2

I'm creating a from like this :

{!! Form::text('name', null, [
              'class' => 'form-control',
              'placeholder'=>'Name',
              "required" => "required|regex:/(^[A-Za-z0-9]+$)+/",
              'maxlength' => 55,
              'minlength' => 5                  
              ])
!!}

I want to make sure that user can't input just blank space more than five times. But this regex:/(^[A-Za-z0-9]+$)+/ doesn't work. Everytime I input space more than 5 times, it's always valid. So How to prevent this thing...???

I have tried 'field'=> 'regex:/(^[A-Za-z0-9 ]+$)+/'from this link : Laravel - Validate only letters, numbers and spaces using regex. It didn't work for me

Upvotes: 1

Views: 1057

Answers (1)

Maryadi Poipo
Maryadi Poipo

Reputation: 1478

Finally I found the answer :

  {!! Form::text('name', null, [
         'class' => 'form-control',
         'placeholder'=>'Name',
         "required" => 'required',
         'maxlength' => 55,
         'minlength' => 5,
         'pattern' => ".*\S+.*"
         ])
     !!}

So I just need to add 'pattern' => ".*\S+.*" then blank space/white space will be seen as an invalid input.

Upvotes: 3

Related Questions