SHA-512 Hash Regex for JavaScript
/^[a-f0-9]{128}$/iWhat this pattern does
This page provides a lightweight, single-purpose regular expression for matching sha-512 hash, 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
// SHA-512 Hash
// ReDoS-safe | RegexVault — Security > Password Formats
const sha512HashRegex = /^[a-f0-9]{128}$/i;
function validateSha512Hash(input: string): boolean {
return sha512HashRegex.test(input);
}
// Example
console.log(validateSha512Hash("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e")); // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e | cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9c |
| — | cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3eXX |
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
SHA-512 is computationally slightly faster on 64-bit systems than SHA-256 due to internal 64-bit operations. For general hashing, SHA-256 is more widely supported.
Technical Notes
SHA-512 produces 512-bit (128 hex char) digests. Part of the SHA-2 family. Commonly used for HMAC signatures, certificate fingerprints, and file integrity. For passwords, use within PBKDF2-SHA512 or Argon2.
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