Twilio Auth Token / SID Regex for JavaScript
/^(AC[a-z0-9]{32}|SK[a-z0-9]{32}|[a-f0-9]{32})$/iWhat this pattern does
This page provides a well-structured, multi-part regular expression for matching twilio auth token / sid, ported and verified for JavaScript. In security-sensitive code, using an unverified regex can open the door to both false positives and denial-of-service attacks. 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
// Twilio Auth Token / SID
// ReDoS-safe | RegexVault — Security > API Keys & Tokens
const twilioAuthTokenSidRegex = /^(AC[a-z0-9]{32}|SK[a-z0-9]{32}|[a-f0-9]{32})$/i;
function validateTwilioAuthTokenSid(input: string): boolean {
return twilioAuthTokenSidRegex.test(input);
}
// Example
console.log(validateTwilioAuthTokenSid("ACa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4")); // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
ACa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4 | AC_short |
SKa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4 | BCa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4 |
a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4 | ACa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4X |
When to use this pattern
This pattern is drawn from the Security > API Keys & Tokens 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
Twilio Auth Tokens are the master credential — prefer API Keys with limited scope. A leaked Auth Token allows sending bulk SMS from your account, triggering massive charges and potential spam reports.
Technical Notes
Twilio Account SID: AC + 32 hex chars. Auth Token: 32 hex chars (no prefix). API Key SID: SK + 32 hex chars. Auth Tokens have full account access. API Keys can be scoped and are preferred over Auth Tokens.
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