MD5 Hash (Deprecated — Detection Only) Regex for JavaScript
/^[a-f0-9]{32}$/iWhat this pattern does
This page provides a lightweight, single-purpose regular expression for matching md5 hash (deprecated — detection only), 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
// MD5 Hash (Deprecated — Detection Only)
// ReDoS-safe | RegexVault — Security > Password Formats
const md5HashDeprecatedDetectionOnlyRegex = /^[a-f0-9]{32}$/i;
function validateMd5HashDeprecatedDetectionOnly(input: string): boolean {
return md5HashDeprecatedDetectionOnlyRegex.test(input);
}
// Example
console.log(validateMd5HashDeprecatedDetectionOnly("d41d8cd98f00b204e9800998ecf8427e")); // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
d41d8cd98f00b204e9800998ecf8427e | d41d8cd98f00b204e9800998ecf8427 |
098f6bcd4621d373cade4e832627b4f6 | d41d8cd98f00b204e9800998ecf8427eX |
| — | ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ |
When to use this pattern
This pattern is drawn from the Security > Password Formats 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
MD5 hashes of passwords can be cracked in milliseconds with GPU rainbow tables for passwords under 10 characters. A database of MD5-hashed passwords is effectively a plaintext database for short passwords.
Technical Notes
MD5 is cryptographically broken — collision attacks are trivial, preimage attacks are feasible. Never use MD5 for password hashing or security purposes. Use only for checksums where collision resistance is not required (e.g., non-security file deduplication). Include this pattern only for detection/migration purposes.
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