respect-validation/docs/rules/CreditCard.md
Henrique Moody a37cac7142
Invert the behaviour of NoWhitespace
Since we have the ability to use `not` as a prefix, having rules that
validate negative behavior makes them a bit inflexible, verbose, and
harder to understand.

This commit will refactor the `NoWhitespace` rule by inverting its
behaviour and renaming it to `Spaced`. Although this is a breaking
change, users will still be able to have a similar behavior with the
prefix `not` + `Spaced`.
2025-12-29 09:11:01 +01:00

2.8 KiB

CreditCard

  • CreditCard()
  • CreditCard(string $brand)

Validates a credit card number.

v::creditCard()->isValid('5376 7473 9720 8720'); // true
v::creditCard()->isValid('5376-7473-9720-8720'); // true
v::creditCard()->isValid('5376.7473.9720.8720'); // true

v::creditCard('American_Express')->isValid('340316193809364'); // true
v::creditCard('Diners_Club')->isValid('30351042633884'); // true
v::creditCard('Discover')->isValid('6011000990139424'); // true
v::creditCard('JCB')->isValid('3566002020360505'); // true
v::creditCard('Mastercard')->isValid('5376747397208720'); // true
v::creditCard('Visa')->isValid('4024007153361885'); // true
v::creaditCard('RuPay')->isValid('6062973831636410') // true

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)
  • RuPay ('RuPay' or CreditCard::RUPAY)

It ignores any non-numeric characters, use Digit, Spaced, or Regex when appropriate.

v::digit()->creditCard()->isValid('5376747397208720'); // true

Templates

CreditCard::TEMPLATE_STANDARD

Mode Template
default {{subject}} must be a valid credit card number
inverted {{subject}} must not be a valid credit card number

CreditCard::TEMPLATE_BRANDED

Mode Template
default {{subject}} must be a valid {{brand|raw}} credit card number
inverted {{subject}} must not be a valid {{brand|raw}} credit card number

Template placeholders

Placeholder Description
brand
subject The validated input or the custom validator name (if specified).

Categorization

  • Banking

Changelog

Version Description
2.2.4 RuPay is now supported as a brand
1.1.0 Allow the define credit card brand
0.3.9 Created

See also: