Apple IDFA / Google GAID (Advertising ID) Regex for PHP
/^[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 PHP. 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 PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.
Php Implementation
<?php
// Apple IDFA / Google GAID (Advertising ID)
// ReDoS-safe | RegexVault — Identity & PII > Digital Identity
define('APPLE_IDFA_GOOGLE_GAID_ADVERTISING_ID_PATTERN', '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/');
function validate_apple_idfa_google_gaid_advertising_id(string $input): bool {
return (bool) preg_match(APPLE_IDFA_GOOGLE_GAID_ADVERTISING_ID_PATTERN, $input);
}
// Example
var_dump(validate_apple_idfa_google_gaid_advertising_id("6D92078A-85A5-4F7E-A9D7-1A9A5A5A5A5A")); // bool(true)Test 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 PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. 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