GithubHelp home page GithubHelp logo

udokmeci / yii2-phone-validator Goto Github PK

View Code? Open in Web Editor NEW
35.0 3.0 17.0 9 KB

Yii2 phone validator is a validator uses phone number util to validate and format the phone number attribute of model.

PHP 100.00%

yii2-phone-validator's Introduction

yii2-phone-validator

Yii2 phone validator is a validator uses phone number util to validate and format the phone number attribute of model.

How to use?

##Installation with Composer Just add the line under require object in your composer.json file.

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

then run

$> composer update

##Configuration Now add following in to your model rules. ###Note: ISO 3166-1 alpha-2 codes are required for country attribute. You can use db-regions for countries list.

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

##Advanced The country and country_code attributes are tried if country or countryAttribute is not specified.

  // 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],  

Any forks are welcome.

yii2-phone-validator's People

Contributors

julianrutten avatar udokmeci avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

yii2-phone-validator's Issues

Release last changes?

This repo has been on 'dev-master' for years now to grab those latest commits. Could you release them? If its breaking for you just give it a new major. Would hate a random commit in here (even after all those years) to break in-production code.

Bence isValidNumberForRegion metodunu kullanmalısın.

Merhaba. Öncelikle emeğinize sağlık fakat bir problem var sanırım. Teyit ederseniz çok sevinirim.

$numberProto = $phoneUtil->parse('+905428488888', 'AF');
$isValidNumber = $phoneUtil->isValidNumber($numberProto);    ===>  true
$numberProto = $phoneUtil->parse('+905428488888', 'AF');
$isValidNumberForRegion = $phoneUtil->isValidNumberForRegion($numberProto,'AF');  ===> false

https://github.com/udokmeci/yii2-phone-validator/blob/master/src/udokmeci/yii2PhoneValidator/PhoneValidator.php#L66 bu satırın isValidNumberForRegion bu metod ile değişmesi gerekiyor.

phone number is not getting saved

hi,

my model code

[['phone_number'], 'udokmeci\yii2PhoneValidator\PhoneValidator','country'=>'IN'],

data i entered is 9809****30 (10 digit valid Indian phone number) the data which is getting stored in db is 91 which is our country code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.