I want to know if I have to use a string or an integer for a phone number?
I have tried an integer
but I have a problem in my validation.
...
table->integer('phone');
...
In my validation, I must have between 8 and 11 characters.
I have tried this, but it doesn't work:
'phone' => 'required|numeric|between:8,11',
I think the string
is better?
If you want to do some calculations with the numbers
which you going to be storing (inserting), then you have to use int
(in Laravel migration: it is integer
) as the data type of the field
. However If you do not want to do some calculations with it, then use the data type as varchar
(in Laravel migration: it is string
) as the data type of the field.
So, when it comes to storing Phone numbers
, you can use the
varchar
data type as you do not have to do calculations with Phone
numbers.
So in this case, your validation should be this:
'phone' => 'required|string|min:8|max:11'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With