freetense/yii2-phone-validator

Yii2 Phone validator 包装器,基于 PhoneNumberUtil 库,也被 Android 设备使用

安装次数: 1,785

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 18

类型:validator

1.0.1 2016-06-14 06:07 UTC

This package is auto-updated.

Last update: 2023-11-29 02:43:07 UTC


README

Yii2 phone validator 是一个使用 phone number util 来验证和格式化模型中电话号码属性的验证器。

如何使用?

## 使用 Composer 安装 仅需在您的 composer.json 文件的 require 对象下添加以下行。

{
  "require": {
    "udokmeci/yii2-phone-validator" : "~1.0.1"
  }
}

然后运行

$> composer update

## 配置 现在将以下内容添加到您的 model 规则中。### 注意:国家属性需要 ISO 3166-1 alpha-2 代码。您可以使用 db-regions 获取国家列表。

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
          [['name', 'country'], 'string', 'max' => 50],
          // add this line
          [['phone'], 'udokmeci\yii2PhoneValidator\PhoneValidator'],
        ];
    }

## 高级 如果未指定 countrycountryAttribute,则会尝试使用 countrycountry_code 属性。

  // All phones will be controlled according to Turkey and formatted to TR Phone Number
  [['phone'], 'udokmeci\yii2PhoneValidator\PhoneValidator','country'=>'TR'],// 

  //All phones will be controlled according to value of $model->country_code
  [['phone'], 'udokmeci\yii2PhoneValidator\PhoneValidator','countryAttribute'=>'country_code'],

  //All phones will be controlled according to value of $model->country_code
  //If model has not a country attribute then phone will not be validated
  //If phone is a valid one will be formatted for International Format. default behavior.
  [['phone'], 'udokmeci\yii2PhoneValidator\PhoneValidator','countryAttribute'=>'country_code','strict'=>false,'format'=>true],  

欢迎任何分支。