aleksandro-del-piero/validate-phone 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aleksandro-del-piero/validate-phone

最新稳定版本:1.0.0

Composer 安装命令:

composer require aleksandro-del-piero/validate-phone

包简介

Package for validation phone number

README 文档

README

With the help of this package, you can validate a mobile phone number.

Installation

You can install the package via composer:

composer require aleksandro_del_piero/validate_phone

Publish configuration file (optional). This command will publish a configuration file in your application. After that, you will be able to find the configuration file in the directory config/validate_phone.php:

php artisan vendor:publish --provider="AleksandroDelPiero\ValidatePhone\ValidatePhoneServiceProvider" --tag="config"

Documentation

Using validation form requests:

Create a validation file following the example:

php artisan make:request ValidatePhoneFormRequest

In the created file, edit the validation rules:

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

or with using rule file:

use AleksandroDelPiero\ValidatePhone\Rules\ValidatePhoneRule;

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

In the translation file you must add a translation that will be used when a validation error occurs (by default path: lang/en/validation.php):

validation.php  

    return [
    ... 
     'validate_phone' => 'my custom message for phone validation',
    ...
    ]

Using validation in controller.

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']
        ]);
    }

or with using rule file:

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'))]
        ]);
    }

Change the validation rules.

If you want to change the validation rules, you can do this in the published configuration file along the path 'config/validate_phone.php'

return [
    'regular_expression' => '/^[\+]380(39|50|6[3|6-8]|9[1-9])[0-9]{7}$/'
];

After changing the configuration file, it is advisable to run the command to clear the cache:

php artisan optimize:clear

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-10