REGEXVAULTv2.0
Finance/Card Numbers
Verified Safe

Card Expiry Date (MM/YY or MM/YYYY) Regex for Go

/^(0[1-9]|1[0-2])/(?:20[0-9]{2}|[2-9][0-9])$/

What this pattern does

This page provides a well-structured, multi-part regular expression for matching card expiry date (mm/yy or mm/yyyy), ported and verified for Go. Financial data validation has zero tolerance for false negatives — a missed invalid entry can corrupt downstream calculations. The snippet below is ready to drop into your Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.

Go Implementation

Go
// Card Expiry Date (MM/YY or MM/YYYY)
// ReDoS-safe | RegexVault — Finance > Card Numbers

package validation

import "regexp"

var cardExpiryDateMmyyOrMmyyyyRe = regexp.MustCompile(`^(0[1-9]|1[0-2])/(?:20[0-9]{2}|[2-9][0-9])$`)

func ValidateCardExpiryDateMmyyOrMmyyyy(s string) bool {
    return cardExpiryDateMmyyOrMmyyyyRe.MatchString(s)
}

// Example
// fmt.Println(ValidateCardExpiryDateMmyyOrMmyyyy("01/24")) // true

Test Cases

Matches (Valid)
Rejects (Invalid)
01/2400/24
12/2913/24
06/20251/24
01/209901/24/00
01-24
01/9
01/199

When to use this pattern

This pattern is drawn from the Finance > Card Numbers category and carries a ReDoS-safe certification. That matters for Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

A card expires at the end of the expiry month (not the 1st). 06/24 is valid until June 30, 2024 23:59:59. Do not reject on the expiry month's first day.

Technical Notes

Capture group 1: month (01-12), group 2: year (2-digit or 4-digit). 2-digit years in the range 20-99 map to 2020-2099. Cards expired but still within the grace period may still be valid — check against today's date at application level.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern