Privacy Policy Version Identifier Regex for JavaScript
/^v([0-9]+)\.([0-9]+)(?:\.([0-9]+))?(?:-([a-zA-Z0-9]+))?$/iWhat this pattern does
This page provides a comprehensive, battle-tested regular expression for matching privacy policy version identifier, 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
// Privacy Policy Version Identifier
// ReDoS-safe | RegexVault — Identity & PII > Consent & Compliance
const privacyPolicyVersionIdentifierRegex = /^v([0-9]+)\.([0-9]+)(?:\.([0-9]+))?(?:-([a-zA-Z0-9]+))?$/i;
function validatePrivacyPolicyVersionIdentifier(input: string): boolean {
return privacyPolicyVersionIdentifierRegex.test(input);
}
// Example
console.log(validatePrivacyPolicyVersionIdentifier("v1.0")); // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
v1.0 | 1.0 |
v2.1.0 | v1 |
v3.0.1-gdpr | v1.0.0.0 |
v1.2.3 | v.1.0 |
v10.0 | version-1.0 |
When to use this pattern
This pattern is drawn from the Identity & PII > Consent & Compliance 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
Material changes to a privacy policy (new data uses, new third-party sharing) require fresh consent under GDPR. Version tracking allows identification of which users need re-consent after a policy update.
Technical Notes
Capture groups: 1=major, 2=minor, 3=patch, 4=label (e.g., 'gdpr', 'ccpa'). Store the version of the privacy policy that was in effect when each user's consent was collected. Consent tied to a specific policy version — material changes may require re-consent.
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