N
N
Nikifor Makarov2014-11-11 13:58:23
Laravel
Nikifor Makarov, 2014-11-11 13:58:23

How to create a phone field in Laravel?

Can you tell me how to organize the 'phone' field in Laravel with validation? The field format should be +7xxxxxxxxxx .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gladkovskiy, 2014-11-11
@nimak

For the convenience of validation, use the preliminary division of the input result into components: at least the country code and the rest of the number. Validate input by number length. Store in the database as text with a length limit, without special characters - just numbers. When outputting, you can already impose the formatting that you need and in a convenient way (either by a mutator or a presenter).
Tell us more - are there any other tasks in working with the phone, besides just fixing the number? Will you work only with our numbers? Will the user have several phones?

S
Sergey Semenko, 2014-11-11
@abler98

You can add your own validators there, and the field itself can be a regular text field
http://laravel.ru/docs/v4/validation#own

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question