Apple IDFA / Google GAID (Advertising ID) Regex for JavaScript
/^[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 JavaScript. 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 JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.
Javascript Implementation
// Apple IDFA / Google GAID (Advertising ID)
// ReDoS-safe | RegexVault — Identity & PII > Digital Identity
const appleIdfaGoogleGaidAdvertisingIdRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
function validateAppleIdfaGoogleGaidAdvertisingId(input: string): boolean {
return appleIdfaGoogleGaidAdvertisingIdRegex.test(input);
}
// Example
console.log(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 JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. 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