![]() | How to validate addresses |
Sometimes, it is important to use addresses from a client or generate some addresses. If you want to process it, it is good to know if the address is correct. There are two ways to validate it:
Client REGEX verification
You only need to validate your address with this REGEX:
TESTNET: ^[T][a-km-zA-HJ-NP-Z0-9]{25,34}$ MAINNET: ^[R][a-km-zA-HJ-NP-Z0-9]{25,34}$
Node API RPC-JSON verification process
It is safer to use node RPC for verification as it uses encrypt method to check if everything is ok.
There is RPC method ValidateAddress.
Example of call:
curl -X POST http://127.0.0.1:16661/ -H 'Authorization: Basic xxx==' -H 'Content-Type: application/json' -H 'cache-control: no-cache' -d '[{"method":"validateaddress", "params":["TQgjBozrWtNCjCkPZwEDkXgCu7iDo4uraa"], "id":1525052699893}]'
Example of result
{"result":{"isvalid":true,"address":"TQgjBozrWtNCjCkPZwEDkXgCu7iDo4uraa","scriptPubKey":"76a914a16c034cffcf8ef2b45c7e81d96f61e1b2a953de88ac","ismine":false,"iswatchonly":false,"isscript":false},"error":null,"id":0}r