Crypto Transaction Hash (Generic) Regex for JavaScript
/^(?:0x)?[0-9a-fA-F]{64}$/What this pattern does
This page provides a lightweight, single-purpose regular expression for matching crypto transaction hash (generic), ported and verified for JavaScript. Financial data validation has zero tolerance for false negatives — a missed invalid entry can corrupt downstream calculations. 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
// Crypto Transaction Hash (Generic)
// ReDoS-safe | RegexVault — Finance > Crypto
const cryptoTransactionHashGenericRegex = /^(?:0x)?[0-9a-fA-F]{64}$/;
function validateCryptoTransactionHashGeneric(input: string): boolean {
return cryptoTransactionHashGenericRegex.test(input);
}
// Example
console.log(validateCryptoTransactionHashGeneric("0xabcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789")); // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
0xabcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789 | 0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1b |
abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789 | 0xabcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789a |
a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2 | notahash |
| — | 0xGGGG |
When to use this pattern
This pattern is drawn from the Finance > Crypto 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
Transaction hashes are not globally unique across blockchains — the same hash string could theoretically appear on different chains (extremely unlikely but true). Include the chain identifier in your data model.
Technical Notes
Ethereum transactions use the 0x prefix. Bitcoin transactions do not. Both produce 256-bit (64 hex chars) hashes. Solana uses Base58-encoded 64-byte hashes — use a different pattern for Solana txids.
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