REGEXVAULTv2.0
Security/Password Formats
Verified Safe

SHA-1 Hash (Deprecated — Detection Only) Regex for JavaScript

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

What this pattern does

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

Javascript
// SHA-1 Hash (Deprecated — Detection Only)
// ReDoS-safe | RegexVault — Security > Password Formats

const sha1HashDeprecatedDetectionOnlyRegex = /^[a-f0-9]{40}$/i;

function validateSha1HashDeprecatedDetectionOnly(input: string): boolean {
  return sha1HashDeprecatedDetectionOnlyRegex.test(input);
}

// Example
console.log(validateSha1HashDeprecatedDetectionOnly("da39a3ee5e6b4b0d3255bfef95601890afd80709")); // true

Test Cases

Matches (Valid)
Rejects (Invalid)
da39a3ee5e6b4b0d3255bfef95601890afd80709da39a3ee5e6b4b0d3255bfef95601890afd8070
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434dda39a3ee5e6b4b0d3255bfef95601890afd807090
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

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

Git historically used SHA-1 for commit hashing. GitHub and major git hosts have enabled SHA-256 object hashing for new repositories. SHA-1 used in TLS certificates was deprecated in 2017.

Technical Notes

SHA-1 is formally deprecated by NIST. Collision attacks were demonstrated in 2017 (SHAttered attack). Never use for digital signatures, certificates, or password hashing. Use SHA-256 or SHA-3 minimum for all new applications.

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