Bitcoin Address (P2SH — starts with 3) Regex for JavaScript
/^3[a-km-zA-HJ-NP-Z1-9]{25,34}$/What this pattern does
This page provides a well-structured, multi-part regular expression for matching bitcoin address (p2sh — starts with 3), 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
// Bitcoin Address (P2SH — starts with 3)
// ReDoS-safe | RegexVault — Finance > Crypto
const bitcoinAddressP2shStartsWith3Regex = /^3[a-km-zA-HJ-NP-Z1-9]{25,34}$/;
function validateBitcoinAddressP2shStartsWith3(input: string): boolean {
return bitcoinAddressP2shStartsWith3Regex.test(input);
}
// Example
console.log(validateBitcoinAddressP2shStartsWith3("3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy")); // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy | 1A1zP1eP5QGefi2DMPTfTL5SLmv7Divf |
3Ai1JZ8pdJb2ksieUV8FsxSNVJCpoPi8W6 | bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq |
| — | 2J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy |
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
A P2SH address alone does not reveal the underlying script (multisig, timelock, etc.). To verify a multisig arrangement, you need the redeem script, not just the address.
Technical Notes
P2SH addresses start with 3. Commonly used for multisignature wallets and wrapped SegWit (P2SH-P2WPKH). More flexible than P2PKH — can represent complex spending conditions.
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