Reputation: 12568
In Laravel 5.6 I am validating alphabetic characters and spaces only in regex like this..
'name' => 'required|regex:/^[\pL\s\-]+$/u',
This works as far as I can see, I am now trying to validate numbers only and spaces like this..
'telephone' => 'required|regex:/[0-9 ]+/',
But this is not working and allows me to enter 'f4' where it should fail.
Where am I going wrong?
Upvotes: 0
Views: 997
Reputation: 163217
[0-9 ]+
will match 4
in f4
Try using anchors to assert the start and the end of the line ^
and $
Note that this will also match whitespaces only because the character class matches digit or a whitespace one or more times..
Upvotes: 4