Bitcoin Address (P2SH — starts with 3) Regex for PHP
/^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 PHP. 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 PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.
Php Implementation
<?php
// Bitcoin Address (P2SH — starts with 3)
// ReDoS-safe | RegexVault — Finance > Crypto
define('BITCOIN_ADDRESS_P2SH_STARTS_WITH_3_PATTERN', '/^3[a-km-zA-HJ-NP-Z1-9]{25,34}$/');
function validate_bitcoin_address_p2sh_starts_with_3(string $input): bool {
return (bool) preg_match(BITCOIN_ADDRESS_P2SH_STARTS_WITH_3_PATTERN, $input);
}
// Example
var_dump(validate_bitcoin_address_p2sh_starts_with_3("3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy")); // bool(true)Test 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 PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. 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