/yii2-luhn-validator

Yii2 Standalone Validator. Checking the number by Luhn algorithm.

Primary LanguagePHPMIT LicenseMIT

Standalone Luhn validator for Yii2

Checking the number by Luhn algorithm. Look more about Luhn algorithm at wikipedia.

For license information check the LICENSE-file.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require padavvan/yii2-luhn-validator

or add

"padavvan/yii2-luhn-validator": "~1.0.2"

to the require section of your composer.json file.

Usage

Look more about Yii2 validators

public function rules() {
  return [
    ['creditCard', LuhnValidator::className()]
  ];
}

// OR
$model = \yii\base\DynamicModel::validateData(['digits' => '...'], [
    ['digits', LuhnValidator::className()]
]);

// OR
LuhnValidator::check($digits); // return true or false

Tests

cd vendor/padavvan/yii2-luhn-validator
php ../../bin/codecept run