Laravel for Go Alpha

laravel-go-credit-card

Validate card numbers, security codes and expiration dates in Go and Laravel for Go.

Validate card numbers, security codes and expiration dates with Laravel for Go or direct Go calls. The package recognizes 15 brands and follows the verdicts of laravel-validation-rules/credit-card 1.12.3.

Read the docs Source on GitHub

go get github.com/bowerbird-si/laravel-go-credit-card@v0.1.0
Latest release
0.1.0, 2026-12-04
Maintenance
Active
Framework
go.laravel.com v0.2.0 or later
Go
Go 1.27 or later
Licence
MIT

PHP parity

Follows laravel-validation-rules/credit-card 1.12.3 (commit 194f41f4fc7d). Last verified .

Parity level
Full
Abilities
42
Covered
30
Diverged
12
Planned
0
PHP fixtures
830
Coverage by ability
  • factory.make-from-number · Covered · Core · 2 tests
    Factory::makeFromNumber($card_number)
  • factory.priority-order · Covered · Core · 2 tests
    Factory::makeFromNumber brand recognition priority order
  • factory.whitespace · Diverged · Core
    Factory::makeFromNumber whitespace handling vs Card::setCardNumber
  • factory.non-string-input · Covered · Core · 2 tests
    Factory::makeFromNumber non-string and non-integer input handling
  • card.construct-and-state · Diverged
    Card::__construct($card_number = '') default/zero construction and post-error state
  • card.set-number · Covered · Core · 2 tests
    Card::setCardNumber($card_number)
  • card.is-valid-number · Covered · Core · 2 tests
    Card::isValidCardNumber()
  • card.luhn-checksum · Covered · Core · 2 tests
    Luhn checksum check in Card::isValidCardNumber()
  • card.metadata · Covered · Core · 2 tests
    Card::type(), Card::name(), Card::brand()
  • card.pattern-property · Diverged
    Public static Card::$pattern property
  • card.is-valid-cvc · Covered · Core · 2 tests
    Card::isValidCvc($cvc)
  • card.is-valid-cvc-length · Covered · Core · 2 tests
    Card::isValidCvcLength($cvc, $available_lengths = [3, 4])
  • card.marker-contract · Diverged
    Contracts\CreditCard marker interface
  • card.custom-implementation · Diverged
    Custom Card subclass validation in Card::__construct()
  • card.errors-redacted · Diverged · Core
    Exceptions\CreditCardException hierarchy (all 9 exception classes) and error redaction
  • brand.dankort · Covered · 2 tests
    Cards\Dankort
  • brand.forbrugsforeningen · Covered · 2 tests
    Cards\Forbrugsforeningen
  • brand.maestro · Covered · Core · 2 tests
    Cards\Maestro
  • brand.visaelectron · Covered · 2 tests
    Cards\VisaElectron
  • brand.elo · Covered · 2 tests
    Cards\Elo
  • brand.amex · Covered · Core · 2 tests
    Cards\AmericanExpress
  • brand.dinersclub · Covered · 2 tests
    Cards\DinersClub
  • brand.discover · Covered · Core · 2 tests
    Cards\Discovery
  • brand.jcb · Covered · 2 tests
    Cards\Jcb
  • brand.hipercard · Diverged
    Cards\Hipercard
  • brand.mastercard · Covered · Core · 2 tests
    Cards\Mastercard
  • brand.unionpay · Covered · 2 tests
    Cards\UnionPay
  • brand.visa · Covered · Core · 2 tests
    Cards\Visa
  • brand.mir · Covered · 2 tests
    Cards\Mir
  • brand.troy · Covered · 2 tests
    Cards\Troy
  • expiration.validate · Covered · Core · 2 tests
    ExpirationDateValidator::validate($year, $month) and isValid()
  • expiration.year · Diverged · Core
    ExpirationDateValidator year parsing and validation
  • expiration.month · Diverged · Core
    ExpirationDateValidator month parsing and validation
  • expiration.boundaries · Covered · Core · 2 tests
    ExpirationDateValidator month-end and short-month rollover boundaries
  • rule.card-number · Covered · Core · 2 tests
    CardNumber::passes($attribute, $value)
  • rule.card-number.messages · Covered · Core · 3 tests
    CardNumber::message() and CardNumber::MSG_CARD_* constants
  • rule.card-cvc · Covered · Core · 2 tests
    CardCvc::passes, CardCvc::message(), CardCvc::MSG_CARD_CVC_INVALID
  • rule.card-expiration-year · Covered · Core · 2 tests
    CardExpirationYear::passes, message(), MSG_CARD_EXPIRATION_YEAR_INVALID
  • rule.card-expiration-month · Covered · Core · 2 tests
    CardExpirationMonth::passes, message(), MSG_CARD_EXPIRATION_MONTH_INVALID
  • rule.card-expiration-date · Diverged · Core
    CardExpirationDate::passes($attribute, $value)
  • rule.card-expiration-date.messages · Diverged · Core
    CardExpirationDate::message() and MSG_CARD_EXPIRATION_DATE_* constants
  • rule.messages.translation · Diverged
    Laravel trans('validation.credit_card.*') message lookup and custom overrides
Differences from PHP (12)
Factory::makeFromNumber whitespace handling vs Card::setCardNumber
ASCII whitespace is stripped before the brand is recognised, so recognition and direct validation agree; PHP matches the brand first and rejects a leading space or a space inside a prefix.
Card::__construct($card_number = '') default/zero construction and post-error state
A card is an immutable validated value: a failed validation returns an error and leaves no half-updated instance, and "0" is checked as a one-digit number instead of being treated as unset.
Public static Card::$pattern property
Built-in brand rules are fixed and a custom brand is a typed specification; PHP exposes a public static pattern on each card class that a program can change.
Contracts\CreditCard marker interface
Cards and brands are concrete types; PHP's marker interface is empty and carries no behaviour.
Custom Card subclass validation in Card::__construct()
A custom card is a typed specification checked when it is built, with the same checks as PHP's runtime checks on a subclass.
Exceptions\CreditCardException hierarchy (all 9 exception classes) and error redaction
Errors name the failed check and never contain the card number or the CVC; PHP's exception messages contain the card number.
Cards\Hipercard
Both Hipercard prefix rules are anchored at the start of the number; PHP's second rule matches anywhere in the string, so some longer numbers fail on length in PHP and match no brand in the port.
ExpirationDateValidator year parsing and validation
One clock supplies the century for two-digit years and the comparison date, and a NUL byte is invalid input; PHP mixes the system clock with the test clock and trims NUL bytes.
ExpirationDateValidator month parsing and validation
A NUL byte is invalid input; PHP trims it from both ends of the month.
CardExpirationDate::passes($attribute, $value)
The four-digit year is kept as parsed, a NUL byte and a format token the port does not support are malformed input, and a format needs at least one token; PHP expands years below 100 to the current century, raises an uncaught ValueError on NUL and parses every DateTime token.
CardExpirationDate::message() and MSG_CARD_EXPIRATION_DATE_* constants
The rule is stateless, so each value gets its own failure message; a reused PHP rule reports the message of its previous failure.
Laravel trans('validation.credit_card.*') message lookup and custom overrides
Rules return a default English message and export PHP's translation keys as constants; PHP returns the key itself and ships no translations.

Built on

Go modules: github.com/bowerbird-si/laravel-go-credit-card · Upstream notices

Documentation