定制 byteweld/laravel-validation-rules 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

byteweld/laravel-validation-rules

最新稳定版本:v1.0.2

Composer 安装命令:

composer require byteweld/laravel-validation-rules

包简介

Custom validation rules for Laravel.

README 文档

README

A package to add custom validation rules for Laravel, including country-based phone number validation.

🚀 Features

  • Country-based phone number validation.
  • International phone number validation.
  • Easy integration with Laravel validation.
  • Supports multiple countries (more coming soon).

📦 Installation

You can install the package via Composer:

composer require byteweld/laravel-validation-rules

After installation, Laravel will automatically discover the service provider.

If you're using Laravel <5.5, you need to add the service provider manually in config/app.php:

'providers' => [
    Byteweld\ValidationRules\Providers\ValidationServiceProvider::class,
],

🛠 Usage

You can use the validation rules in Laravel’s validation system.

📞 Country-Based Phone Number Validation

Rule: phone_number:{country}

This rule validates a phone number based on country-specific criteria.

Example Usage

$request->validate([
    'phone' => 'required|phone_number:india',
]);

Validation Logic for India

✅ Must contain only numbers
✅ Length must be exactly 10 digits
✅ Must start with 6, 7, 8, or 9

🌎 International Phone Number Validation

Rule: international_phone_number:{country}

This rule validates international phone numbers according to country-specific formats.

Example Usage

$request->validate([
    'phone' => 'required|international_phone_number:india',
]);

Validation Logic for India

✅ Must contain only numbers
✅ Length must be exactly 13 characters
✅ Must start with +91 followed by a 10-digit mobile number
✅ The number must start with 6, 7, 8, or 9

🧪 Running Tests

To ensure everything works as expected, run the tests:

php artisan test

🛠 Customization

You can extend the validation for more countries. To contribute, submit a pull request on GitHub.

📌 Versioning

This package follows semantic versioning (MAJOR.MINOR.PATCH).

  • v1.0.0 - Initial release with basic validation.
  • v1.1.0 - Added support for international phone validation.
  • Future versions will include more country rules.

📜 License

This package is open-source and licensed under the MIT License.

🔗 Contributing

We welcome contributions! If you find a bug or want to add more validation rules, feel free to:

  1. Fork the repo.
  2. Create a new branch.
  3. Submit a pull request.

📬 Support

For any issues, open an issue on GitHub:
🔗 GitHub Issues

📢 Next Steps

✅ Add support for more countries
✅ Add a configuration file for dynamic country validation
✅ Improve test coverage

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-02