Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/laravel-validation-rules/credit-card
Credit Card Validation
https://github.com/laravel-validation-rules/credit-card
credit-card creditcard debit-card laravel laravel-5-package php validation validator
Last synced: 3 days ago
JSON representation
Credit Card Validation
- Host: GitHub
- URL: https://github.com/laravel-validation-rules/credit-card
- Owner: laravel-validation-rules
- License: apache-2.0
- Created: 2017-09-18T06:42:17.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-16T12:34:00.000Z (9 months ago)
- Last Synced: 2024-05-18T19:45:17.245Z (8 months ago)
- Topics: credit-card, creditcard, debit-card, laravel, laravel-5-package, php, validation, validator
- Language: PHP
- Homepage: https://laravel-validation-rules.github.io/
- Size: 129 KB
- Stars: 220
- Watchers: 13
- Forks: 66
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Validator Rules - Credit Card
This rule will validate that a given credit card **number**, **expiration date** or **cvc** is valid.
## Installation
```bash
composer require laravel-validation-rules/credit-card
```## Usage
### As FormRequest
```php
['required', new CardNumber],
'expiration_year' => ['required', new CardExpirationYear($this->get('expiration_month'))],
'expiration_month' => ['required', new CardExpirationMonth($this->get('expiration_year'))],
'cvc' => ['required', new CardCvc($this->get('card_number'))]
];
}
}
```### Card number
#### From request
```php
$request->validate(
['card_number' => '37873449367100'],
['card_number' => new LVR\CreditCard\CardNumber]
);
```
#### Directly
```php
(new LVR\CreditCard\Cards\Visa)
->setCardNumber('4012888888881881')
->isValidCardNumber()
```### Card expiration
#### From request
```php
// CardExpirationYear requires card expiration month
$request->validate(
['expiration_year' => '2017'],
['expiration_year' => ['required', new LVR\CreditCard\CardExpirationYear($request->get('expiration_month'))]]
);// CardExpirationMonth requires card expiration year
$request->validate(
['expiration_month' => '11'],
['expiration_month' => ['required', new LVR\CreditCard\CardExpirationMonth($request->get('expiration_year'))]]
);// CardExpirationDate requires date format
$request->validate(
['expiration_date' => '02-18'],
['expiration_date' => ['required', new LVR\CreditCard\CardExpirationDate('my')]]
);
```
#### Directly
```php
LVR\CreditCard\Cards\ExpirationDateValidator(
$expiration_year,
$expiration_month
)->isValid();// Or static
LVR\CreditCard\Cards\ExpirationDateValidator::validate(
$expiration_year,
$expiration_month
);
```### Card CVC
#### From request
```php
// CardCvc requires card number to determine allowed cvc length
$request->validate(
['cvc' => '123'],
['cvc' => new LVR\CreditCard\CardCvc($request->get('card_number'))]
);```
#### Directly
```php
LVR\CreditCard\Cards\Card::isValidCvcLength($cvc);
```### License
This project is licensed under an Apache 2.0 license which you can find
[in this LICENSE](https://github.com/laravel-validation-rules/credit-card/blob/master/LICENSE).### Feedback
If you have any feedback, comments or suggestions, please feel free to open an
issue within this repository!