N
N
Nikifor Makarov2014-11-14 14:17:29
Laravel
Nikifor Makarov, 2014-11-14 14:17:29

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

2 answer(s)
A
Alexander Zelenin, 2014-11-14
@nimak

don't know how to apply, go to the php.net documentation. There are always examples.
Totally lazy.

S
Sergey Gladkovskiy, 2014-11-14
@SMGladkovskiy

...
$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 question

Ask a Question

731 491 924 answers to any question