Bitcoin Bech32 Address (Native SegWit — bc1) Regex for PHP
/^bc1[ac-hj-np-z02-9]{11,71}$/What this pattern does
This page provides a lightweight, single-purpose regular expression for matching bitcoin bech32 address (native segwit — bc1), 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 Bech32 Address (Native SegWit — bc1)
// ReDoS-safe | RegexVault — Finance > Crypto
define('BITCOIN_BECH32_ADDRESS_NATIVE_SEGWIT_BC1_PATTERN', '/^bc1[ac-hj-np-z02-9]{11,71}$/');
function validate_bitcoin_bech32_address_native_segwit_bc1(string $input): bool {
return (bool) preg_match(BITCOIN_BECH32_ADDRESS_NATIVE_SEGWIT_BC1_PATTERN, $input);
}
// Example
var_dump(validate_bitcoin_bech32_address_native_segwit_bc1("bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq")); // bool(true)Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq | BC1QAR0SRRR7XFKVY5L643LYDNW9RE59GTZZWF5MDQ |
bc1q42lja79elem0anu8q8s3h2n687re9jax556pnm | tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx |
| — | 1A1zP1eP5QGefi2DMPTfTL5SLmv7Divf |
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
Testnet Bech32 addresses start with tb1 (not bc1). Signet uses tb1. Never send mainnet funds to a testnet address — the coins will be unrecoverable.
Technical Notes
Bech32 uses the charset qpzry9x8gf2tvdw0s3jn54khce6mua7l. P2WPKH: bc1q + 39 chars (42 total). P2WSH: bc1q + 59 chars (62 total). Taproot (P2TR): bc1p + 58 chars. Case-insensitive but conventionally lowercase.
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