Twilio Auth Token / SID Regex for PHP
/^(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 PHP. 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 PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.
Php Implementation
<?php
// Twilio Auth Token / SID
// ReDoS-safe | RegexVault — Security > API Keys & Tokens
define('TWILIO_AUTH_TOKEN_SID_PATTERN', '/^(AC[a-z0-9]{32}|SK[a-z0-9]{32}|[a-f0-9]{32})$/');
function validate_twilio_auth_token_sid(string $input): bool {
return (bool) preg_match(TWILIO_AUTH_TOKEN_SID_PATTERN, $input);
}
// Example
var_dump(validate_twilio_auth_token_sid("ACa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4")); // bool(true)Test 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 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
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