Phone Number Validation in Laravel

In this article, I’m going to show how to validate mobile number in Laravel. Let’s get started:

Table of Contents

  1. Ways of Validation
  2. Example

Ways of Validation

We ca follow some ways to validate mobile number. Have a look at some ways:

// way 1
$this->validate($request, [
    'phone' => 'required|digits:10'

// way 2
$this->validate($request, [
    'phone' => 'required|min:10|numeric'

// way 3
$this->validate($request, [
    'phone' => 'required|numeric|between:9,11'

// way 4
$this->validate($request, [
    'phone' => 'required|regex:/(01)[0-9]{9}/'

// way 5
$this->validate($request, [
    'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10'


Let’s make a simple form:

<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>Phone Number Validation in Laravel</title>
  <link rel="stylesheet" href="" />
<div class="container">
    <h2 style="margin-top: 10px;">Phone Number Validation in Laravel -</h2>
    @if ($message = Session::get('success'))
    <div class="alert alert-success alert-block">
        <button type="button" class="close" data-dismiss="alert">×</button>
          <strong>{{ $message }}</strong>

    <form method="post" action="{{url('store')}}">
      <div class="form-group">
        <label for="formGroupExampleInput">Name</label>
        <input type="text" name="name" class="form-control" id="formGroupExampleInput" placeholder="Please enter name">
        <span class="text-danger">{{ $errors->first('name') }}</span>

      <div class="form-group">
        <label for="formGroupExampleInput2">Email</label>
        <input type="email" name="email" class="form-control" id="formGroupExampleInput2" placeholder="Please enter password">
        <span class="text-danger">{{ $errors->first('email') }}</span>

      <div class="form-group">
        <label for="formGroupExampleInput2">Phone Number</label>
        <input type="text" name="phone" class="form-control" id="formGroupExampleInput2" placeholder="Please enter mobile number">
        <span class="text-danger">{{ $errors->first('phone') }}</span>

      <div class="form-group">
       <button type="submit" class="btn btn-success">Submit</button>

Apply validation rules in controller:

public function store(Request $request)
            'name' => 'required',
            'phone' => 'required|digits:10',
            'email' => 'required|email|unique'

    $input = $request->all();
    $user = User::create($input);

    return back()->with('success', 'User added successfully.');

We can use any validation ways from the above.

The routes will look like:


That’s it. Thanks for reading.

Software Engineer | Ethical Hacker & Cybersecurity...

Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.