padavvan/yii2-luhn-validator

1.0.2 2017-07-12 20:19 UTC

This package is not auto-updated.

Last update: 2024-05-12 01:49:26 UTC


README

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