davidnsai/numlock

这是一个用于电话号码验证的CodeIgniter库。

v1.0.0 2024-03-20 10:51 UTC

This package is auto-updated.

Last update: 2024-09-20 12:01:26 UTC


README

这是什么?

Numlock是一个CodeIgniter电话号码验证库。这个库基于Google的# libphonenumber for PHP

安装

目前支持PHP版本8.0到PHP 8.2。

需要PECL mbstring 扩展。

建议使用 composer 来安装库。

$ composer require davidnsai/numlock

您也可以使用任何其他符合PSR-4规范的自动加载器。

使用方法

要在CodeIgniter项目中使用,请打开app/Config/Validation.php文件,并将您的代码修改如下:

<?php
namespace  Config;
use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Validation\StrictRules\CreditCardRules;
use CodeIgniter\Validation\StrictRules\FileRules;
use CodeIgniter\Validation\StrictRules\FormatRules;
use CodeIgniter\Validation\StrictRules\Rules;
use Numlock\ValidatePhone;
 ...
class  Validation  extends  BaseConfig
{
	public  array  $ruleSets  =  [
		Rules::class,
		FormatRules::class,
		FileRules::class,
		CreditCardRules::class,
		ValidatePhone::class,
	];
 ...
 // More code here

上述代码使Numlock的电话号码验证方法可用于整个应用程序中的验证。目前,Numlock提供了以下方法可供使用:

	is_valid_phone(string  $phonenumber):  bool
	valid_phone_country(string  $phonenumber,  string  $iso_country_code):  bool

要验证您的输入,只需将这些方法添加到验证数组中。valid_phone_country方法。使用2个字母的ISO国家代码作为参数进行验证。

运行测试

要运行测试,请使用PHPUnit。

要本地运行测试,请运行./vendor/bin/phpunit脚本。