REGEXVAULTv2.0
Security/Password Formats
Verified Safe

SHA-256 Hash Regex for JavaScript

/^[a-f0-9]{64}$/i

What this pattern does

This page provides a lightweight, single-purpose regular expression for matching sha-256 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

Javascript
// SHA-256 Hash
// ReDoS-safe | RegexVault — Security > Password Formats

const sha256HashRegex = /^[a-f0-9]{64}$/i;

function validateSha256Hash(input: string): boolean {
  return sha256HashRegex.test(input);
}

// Example
console.log(validateSha256Hash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")); // true

Test Cases

Matches (Valid)
Rejects (Invalid)
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855X

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-256 of a password without salt is equivalent to MD5 for dictionary attacks — it is fast to compute and has no iteration cost. Always use a proper KDF (Key Derivation Function) for password storage.

Technical Notes

SHA-256 is part of the SHA-2 family, still cryptographically secure. Used for certificates, code signing, TLS, and file integrity. For password hashing, always use SHA-256 within a proper password hashing function (PBKDF2, Argon2) — raw SHA-256 alone is not suitable for passwords.

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