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 testsFactory::makeFromNumber($card_number) -
factory.priority-order· Covered · Core · 2 testsFactory::makeFromNumber brand recognition priority order -
factory.whitespace· Diverged · CoreFactory::makeFromNumber whitespace handling vs Card::setCardNumber -
factory.non-string-input· Covered · Core · 2 testsFactory::makeFromNumber non-string and non-integer input handling -
card.construct-and-state· DivergedCard::__construct($card_number = '') default/zero construction and post-error state -
card.set-number· Covered · Core · 2 testsCard::setCardNumber($card_number) -
card.is-valid-number· Covered · Core · 2 testsCard::isValidCardNumber() -
card.luhn-checksum· Covered · Core · 2 testsLuhn checksum check in Card::isValidCardNumber() -
card.metadata· Covered · Core · 2 testsCard::type(), Card::name(), Card::brand() -
card.pattern-property· DivergedPublic static Card::$pattern property -
card.is-valid-cvc· Covered · Core · 2 testsCard::isValidCvc($cvc) -
card.is-valid-cvc-length· Covered · Core · 2 testsCard::isValidCvcLength($cvc, $available_lengths = [3, 4]) -
card.marker-contract· DivergedContracts\CreditCard marker interface -
card.custom-implementation· DivergedCustom Card subclass validation in Card::__construct() -
card.errors-redacted· Diverged · CoreExceptions\CreditCardException hierarchy (all 9 exception classes) and error redaction -
brand.dankort· Covered · 2 testsCards\Dankort -
brand.forbrugsforeningen· Covered · 2 testsCards\Forbrugsforeningen -
brand.maestro· Covered · Core · 2 testsCards\Maestro -
brand.visaelectron· Covered · 2 testsCards\VisaElectron -
brand.elo· Covered · 2 testsCards\Elo -
brand.amex· Covered · Core · 2 testsCards\AmericanExpress -
brand.dinersclub· Covered · 2 testsCards\DinersClub -
brand.discover· Covered · Core · 2 testsCards\Discovery -
brand.jcb· Covered · 2 testsCards\Jcb -
brand.hipercard· DivergedCards\Hipercard -
brand.mastercard· Covered · Core · 2 testsCards\Mastercard -
brand.unionpay· Covered · 2 testsCards\UnionPay -
brand.visa· Covered · Core · 2 testsCards\Visa -
brand.mir· Covered · 2 testsCards\Mir -
brand.troy· Covered · 2 testsCards\Troy -
expiration.validate· Covered · Core · 2 testsExpirationDateValidator::validate($year, $month) and isValid() -
expiration.year· Diverged · CoreExpirationDateValidator year parsing and validation -
expiration.month· Diverged · CoreExpirationDateValidator month parsing and validation -
expiration.boundaries· Covered · Core · 2 testsExpirationDateValidator month-end and short-month rollover boundaries -
rule.card-number· Covered · Core · 2 testsCardNumber::passes($attribute, $value) -
rule.card-number.messages· Covered · Core · 3 testsCardNumber::message() and CardNumber::MSG_CARD_* constants -
rule.card-cvc· Covered · Core · 2 testsCardCvc::passes, CardCvc::message(), CardCvc::MSG_CARD_CVC_INVALID -
rule.card-expiration-year· Covered · Core · 2 testsCardExpirationYear::passes, message(), MSG_CARD_EXPIRATION_YEAR_INVALID -
rule.card-expiration-month· Covered · Core · 2 testsCardExpirationMonth::passes, message(), MSG_CARD_EXPIRATION_MONTH_INVALID -
rule.card-expiration-date· Diverged · CoreCardExpirationDate::passes($attribute, $value) -
rule.card-expiration-date.messages· Diverged · CoreCardExpirationDate::message() and MSG_CARD_EXPIRATION_DATE_* constants -
rule.messages.translation· DivergedLaravel 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
- laravel-validation-rules/credit-card: The card validation package this independent Go implementation follows, pinned to version 1.12.3.
Go modules: github.com/bowerbird-si/laravel-go-credit-card
· Upstream notices
Documentation
- OverviewValidate card numbers, security codes and expiration dates with Laravel for Go or direct Go calls. The package recognizes 15 brands and follows the verdicts…
- Getting startedInstall the package and configure validation and session exclusions for a Laravel for Go checkout form.
- Migrating from PHPUse these Go functions and Laravel for Go rules when moving a form from laravel-validation-rules/credit-card.
- ChangelogWhat changed in each release of laravel-go-credit-card: additions, changes and fixes.