Answer the question
In order to leave comments, you need to log in
How to remove unnecessary characters before validation in Laravel?
Hello!
Tell me how to remove all unnecessary characters in Laravel (brackets, spaces, dashes, +) before validation, I get the phone field through a mask like this:
+7 (999) 999 99-99, but you need this field to be validated in this form
79999999999, I know how to remove everything except numbers
preg_replace('/[^\d]/')but I don't know how to apply it.
Answer the question
In order to leave comments, you need to log in
don't know how to apply, go to the php.net documentation. There are always examples.
Totally lazy.
...
$phone = preg_replace('/[^\d]/', '', Input::get('phone')); // получаете значение, санируете.
$validator = Validator::make(
['phone' => $phone ],
['phone' => 'required|numeric|min:10|max:12'], // и так далее - правила валидации
);
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question