Apple IDFA / Google GAID (Advertising ID) Regex for Go
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iWhat this pattern does
This page provides a well-structured, multi-part regular expression for matching apple idfa / google gaid (advertising id), ported and verified for Go. Identity and credential patterns need both correctness and safety, since they're frequent targets for adversarial input. 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
// Apple IDFA / Google GAID (Advertising ID)
// ReDoS-safe | RegexVault — Identity & PII > Digital Identity
package validation
import "regexp"
var appleIdfaGoogleGaidAdvertisingIdRe = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`)
func ValidateAppleIdfaGoogleGaidAdvertisingId(s string) bool {
return appleIdfaGoogleGaidAdvertisingIdRe.MatchString(s)
}
// Example
// fmt.Println(ValidateAppleIdfaGoogleGaidAdvertisingId("6D92078A-85A5-4F7E-A9D7-1A9A5A5A5A5A")) // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
6D92078A-85A5-4F7E-A9D7-1A9A5A5A5A5A | 6D92078A-85A5-4F7E-A9D7-1A9A5A5A5 |
00000000-0000-4000-8000-000000000000 | 6D92078A85A54F7EA9D71A9A5A5A5A5A |
| — | 00000000-0000-0000-0000-000000000000 |
When to use this pattern
This pattern is drawn from the Identity & PII > Digital Identity 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
Since iOS 14.5 (2021), apps must request ATT (App Tracking Transparency) permission before accessing IDFA. A valid UUID format does not mean the user consented — check for the nil UUID (all zeros) as an opt-out signal.
Technical Notes
IDFA (iOS) and GAID (Android) are UUID v4 format advertising identifiers. The nil IDFA (00000000-0000-0000-0000-000000000000) indicates the user has opted out of tracking (iOS 14+ ATT framework). Google allows users to reset GAID at any time.
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