phone number validation, laravel
'phone' => 'required|regex:/(01)[0-9]{9}/'
phone number validation, laravel
'phone' => 'required|regex:/(01)[0-9]{9}/'
validation sellphone laravel
One possible solution would to use regex.
'phone' => 'required|regex:/(01)[0-9]{9}/'
This will check the input starts with 01 and is followed by 9 numbers. By using regex
you dont need the numeric or size validation rules.
If you want to reuse this validation method else where, it would be a good idea to
create your own validation rule for validating phone numbers.
Docs: Custom Validation - https://laravel.com/docs/5.4/validation#custom-validation-rules
In your AppServiceProviders boot method:
Validator::extend('phone_number', function($attribute, $value, $parameters)
{
return substr($value, 0, 2) == '01';
});
This will allow you to use the phone_number validation rule anywhere in your application,
so your form validation could be:
'phone' => 'required|numeric|phone_number|size:11'
In your validator extension you could also check if the $value is numeric and 11
characters long.
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us