respect-validation/docs/rules/CreditCard.md

70 lines
1.9 KiB
Markdown
Raw Permalink Normal View History

2015-01-30 09:40:06 +01:00
# CreditCard
- `CreditCard()`
- `CreditCard(string $brand)`
2015-01-30 09:40:06 +01:00
Validates a credit card number.
```php
v::creditCard()->validate('5376 7473 9720 8720'); // true
v::creditCard()->validate('5376-7473-9720-8720'); // true
v::creditCard()->validate('5376.7473.9720.8720'); // true
v::creditCard('American_Express')->validate('340316193809364'); // true
v::creditCard('Diners_Club')->validate('30351042633884'); // true
v::creditCard('Discover')->validate('6011000990139424'); // true
v::creditCard('JCB')->validate('3566002020360505'); // true
v::creditCard('Mastercard')->validate('5376747397208720'); // true
v::creditCard('Visa')->validate('4024007153361885'); // true
2022-10-22 10:19:57 +02:00
v::creaditCard('RuPay')->validate('6062973831636410') // true
2015-01-30 09:40:06 +01:00
```
The current supported brands are:
- American Express (`'American_Express'` or `CreditCard::AMERICAN_EXPRESS`)
- Diners Club (`'Diners_Club'` or `CreditCard::DINERS_CLUB`)
- Discover (`'Discover'` or `CreditCard::DISCOVER`)
- JCB (`'JCB'` or `CreditCard::JCB`)
- Mastercard (`'American_Express'` or `CreditCard::MASTERCARD`)
- Visa (`'Visa'` or `CreditCard::VISA`)
2022-10-22 10:19:57 +02:00
- RuPay (`'RuPay'` or `CreditCard::RUPAY`)
It ignores any non-numeric characters, use [Digit](Digit.md),
[NoWhitespace](NoWhitespace.md), or [Regex](Regex.md) when appropriate.
2015-01-30 09:40:06 +01:00
```php
v::digit()->creditCard()->validate('5376747397208720'); // true
2015-01-30 09:40:06 +01:00
```
## Categorization
- Banking
## Changelog
2022-10-22 10:19:57 +02:00
| Version | Description |
| ------- | ---------------------------------- |
2023-02-13 23:18:16 +01:00
| 2.2.4 | RuPay is now supported as a brand |
2022-10-22 10:19:57 +02:00
| 1.1.0 | Allow the define credit card brand |
| 0.3.9 | Created |
---
See also:
- [Decimal](Decimal.md)
- [Digit](Digit.md)
- [Iban](Iban.md)
2017-08-18 13:47:36 +02:00
- [Luhn](Luhn.md)
- [NoWhitespace](NoWhitespace.md)
2018-12-11 13:31:50 +01:00
- [Regex](Regex.md)
***
See also:
- [Decimal](Decimal.md)
- [Digit](Digit.md)
- [Iban](Iban.md)
- [Luhn](Luhn.md)
- [NoWhitespace](NoWhitespace.md)
- [Regex](Regex.md)