linusu / bitcoin-address-validator
A simple, easy to use PHP Bitcoin address validator
Installs: 144 518
Dependents: 3
Suggesters: 0
Security: 0
Stars: 53
Watchers: 11
Forks: 29
Open Issues: 5
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-11-09 17:14:13 UTC
README
A simple, easy to use PHP Bitcoin address validator
Usage
Quick start:
use \LinusU\Bitcoin\AddressValidator; // This will return false, indicating invalid address. AddressValidator::isValid('blah'); // This is a valid address and will thus return true. AddressValidator::isValid('1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i'); // This is a Testnet address, it's valid and the function will return true. AddressValidator::isValid('mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs', AddressValidator::TESTNET);
API
isValid($addr, $version)
$addr
: A bitcoin address$version
: The version to test against, defaults toMAINNET
Returns a boolean indicating if the address is valid or not.
typeOf($addr)
$addr
: A bitcoin address
Returns the type of the address.
Constants
The library exposes the following constants.
MAINNET
: Indicates any mainnet address typeTESTNET
: Indicates any testnet address typeMAINNET_PUBKEY
: Indicates a mainnet pay to pubkey hash addressMAINNET_SCRIPT
: Indicates a mainnet pay to script hash addressTESTNET_PUBKEY
: Indicates a testnet pay to pubkey hash addressTESTNET_SCRIPT
: Indicates a testnet pay to script hash address