2

yii2 の正規表現バリデーターを使用して、次の電話番号を検証しようとしています。

+6018-2031218
0060182031218
006018-2031218

このような

 public function rules()
{
    return [
        [['name', 'minimum_order_amount', 'time_order_open', 'time_order_close', 'delivery_fee', 'rank', 'halal', 'featured', 'working_opening_hours', 'working_closing_hours', 'disable_ordering', 'delivery_duration', 'phone_number', 'longitude', 'latitude', 'image', 'status', 'owner_id', 'user_id'], 'required'],
        [['minimum_order_amount', 'delivery_fee', 'rank', 'longitude', 'latitude'], 'number'],
        [['time_order_open', 'time_order_close', 'working_opening_hours', 'working_closing_hours', 'created_at', 'updated_at'], 'safe'],
        [['halal', 'featured', 'disable_ordering', 'delivery_duration', 'status', 'owner_id', 'user_id'], 'integer'],
        [['name', 'phone_number', 'image'], 'string', 'max' => 255],
        [['working_opening_hours','working_closing_hours','time_order_open', 'time_order_close'], 'date', 'format' => 'H:m:s'],
        [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
        [['owner_id'], 'exist', 'skipOnError' => true, 'targetClass' => Owners::className(), 'targetAttribute' => ['owner_id' => 'id']],
        [['phone_number'], 'match', 'pattern' => '/((\+[0-9]{6})|0)[-]?[0-9]{7}/'],
    ];
}

しかし、これらの電話番号の正しい正規表現を取得できません。yii2 でこれを行う別の方法はありますか。

4

1 に答える 1