PHP code example of aleksandro-del-piero / validate-phone

1. Go to this page and download the library: Download aleksandro-del-piero/validate-phone library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aleksandro-del-piero / validate-phone example snippets


    public function rules(): array
    {
        return [
            'phone' => ['validate_phone']
        ];
    }

use AleksandroDelPiero\ValidatePhone\Rules\ValidatePhoneRule;

    public function rules(): array
    {
        return [
            'phone' => [new ValidatePhoneRule(__('validation.validate_phone'))]
        ];
    }
 
validation.php  

    return [
    ... 
     'validate_phone' => 'my custom message for phone validation',
    ...
    ]
 
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        $this->validate($request, [
            'phone' => ['validate_phone']
        ]);
    }
 
namespace App\Http\Controllers;

use AleksandroDelPiero\ValidatePhone\Rules\ValidatePhoneRule;
use Illuminate\Http\Request;

class TestController extends Controller
{
    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        $this->validate($request, [
            'phone' => [new ValidatePhoneRule(__('validation.validate_phone'))]
        ]);
    }
 
return [
    'regular_expression' => '/^[\+]380(39|50|6[3|6-8]|9[1-9])[0-9]{7}$/'
];
 bash
php artisan vendor:publish --provider="AleksandroDelPiero\ValidatePhone\ValidatePhoneServiceProvider" --tag="config"
bash
php artisan make:request ValidatePhoneFormRequest
bash
php artisan optimize:clear