Laravel 8 validation for mobile number

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Hello Dev’s
Now In this article,I will teach you how to make mobile number validation in laravel application. So here we can only 11 digit mobile number then validation digit:11. Also we can do it simply apply to validation to mobile number in laravel 8 application.

Example 1 :

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index(Request $request)
{
  $this->validate($request, [
        'mobile' => 'required|digits:11'
    ]);
}

Example 2 :

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index(Request $request)
{
  $this->validate($request, [
        'mobile' => 'required|numeric|between:10,11'
    ]);
}

Example 3 :

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index(Request $request)
{
  $this->validate($request, [
        'mobile' => 'required|min:11|numeric'
    ]);
}

Example 4 :

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index(Request $request)
{
  $this->validate($request, [
        'mobile' => 'required|regex:/(01)[0-9]{9}/'
    ]);
}

Example 5 :

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index(Request $request)
{
  $this->validate($request, [
        'mobile' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:11'
    ]);
}

Read Also : Laravel validation required if another field is empty

Thanks for read. I hope it help you. For more you can follow us onĀ facebook

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →