Laravel Mobile/Phone Number Validation Example
In this tutorial we will go over the demonstration of laravel phone number validation. it's simple example of laravel mobile number validation. This article goes in detailed on 10 digit mobile number validation in laravel. you will learn phone number validation in laravel.
we most of the requirement to add phone number validation in our laravel application. so i will show how to add mobile validation in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 using regex. you can easily use with your controller method.
I will give you two way to add phone number validation in laravel. so i will just show you controller code and preview here. so you can also follow form validation with laravel with this code: Laravel Form Validation Example.
You can see bellow preview:
Preview:
Example 1:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
class HomeController extends Controller
{
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('createUser');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'phone' => 'required|digits:10',
'email' => 'required|email|unique:users'
]);
$input = $request->all();
$user = User::create($input);
return back()->with('success', 'User created successfully.');
}
}
Example 2:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use Validator;
class HomeController extends Controller
{
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('createUser');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10',
'email' => 'required|email|unique:users'
]);
$input = $request->all();
$user = User::create($input);
return back()->with('success', 'User created successfully.');
}
}
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel 7 Form Validation Tutorial
- Laravel 8/7/6 Google ReCAPTCHA Form Validation Example
- Laravel Validation Check If Value is Not Equal to a Another Field
- Laravel Change Password with Current Password Validation Example
- Laravel Validation for Multiple Files in Array Example
- Laravel Ajax Request with Validation Example
- Laravel - Generate Captcha code and Validation example using BotDetect package
- Laravel File Upload with Validation Example
- Laravel Client Side Validation using Parsley.js Example
- Laravel Create Custom Validation Rule Example