https://github.com/linusu/php-bitcoin-address-validator
💰 A simple, easy to use PHP Bitcoin address validator
https://github.com/linusu/php-bitcoin-address-validator
Last synced: 4 months ago
JSON representation
💰 A simple, easy to use PHP Bitcoin address validator
- Host: GitHub
- URL: https://github.com/linusu/php-bitcoin-address-validator
- Owner: LinusU
- License: mit
- Created: 2014-04-14T15:18:52.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2020-06-03T00:52:47.000Z (about 6 years ago)
- Last Synced: 2025-01-02T00:32:36.707Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 188 KB
- Stars: 53
- Watchers: 11
- Forks: 29
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php-bitcoin-address-validator
A simple, easy to use PHP Bitcoin address validator
## Usage
Quick start:
```php
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 to `MAINNET`
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 type
- `TESTNET`: Indicates any testnet address type
- `MAINNET_PUBKEY`: Indicates a mainnet pay to pubkey hash address
- `MAINNET_SCRIPT`: Indicates a mainnet pay to script hash address
- `TESTNET_PUBKEY`: Indicates a testnet pay to pubkey hash address
- `TESTNET_SCRIPT`: Indicates a testnet pay to script hash address