Giter Site home page Giter Site logo

creditcardvalidator's Introduction

Credit Card Validator

Validates Visa, MasterCard, and American Express credit card numbers.

Installation

Using Composer

This project uses composer to generate a PSR-0 autoloader. Download and install composer into the project root directory, then run:

sudo ./composer.phar install

Usage

$card = new CreditCard()
$card->setNumbder("1234-abcd-sd&*);
$card->setPropertyConstraint('number', new CreditCardNumberConstraint());

$validator = new Validator();
$errors = $validate($card);

$this->assertGreaterThan(0, count($errors));
$this->assertInstanceOf(CreditCardNumberValidationError, $errors[0])

$errors[0]->renderErrorMsg();     // Returns a clever error message

Extending

The validation component included in this package was made to be easily extended. For example, to validate credit card dates, you could

  • Create a AfterTodaysDateConstraint class, which implements the ConstraintInterface
  • Set a validate method on the constraint, which accepts a date, and returns an array of ViolationErrorInterface objects if the date is earlier that today.

You could then set this constraint on the CreditCardModel's date property:

$card->setPropertyConstraint('expDate', new AfterTodaysDateConstraint());

Not that you could also creat new models extending the AbstractModel class, and validate with the same components. For example, you could end up with something like:

$event = new TheEventModelWhichYouCreatedThatExtendsAbstractModel();
$event->setDate("March 08, 2007");
$event->setPropertyConstraint('date', new AfterTodaysDateConstraint());

$validator = new Validator();
$errors = $validator->validate($event);

Testing

This component is unit- and functional-tested using PHPUnit. All test currently pass, running PHP 5.4.10.

Please unit test your pull requests before submitting.

creditcardvalidator's People

Watchers

 avatar  avatar

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.