<p>If you call</p>

<pre><code>bitcoin.address.toOutputScript(address, bitcoin.networks.bitcoin)
</code></pre>

<p>It will throw an error if the address cannot be parsed as P2SH or P2PKH, or if the checksum is not valid. Replace the second argument with <code>bitcoin.networks.testnet</code> for testnet.</p>

CC BY-SA 3.0
2017-04-12T23:15:45.073Z
2017-04-12T23:15:45.073Z
Nick ODell
<p>How would one validate a bitcoin address using the bitcoinjs library? Or is there another way to do this via javascript?</p>

CC BY-SA 3.0
2017-04-12T22:23:54.583Z
Do you mean for a website or app? Or do you just want to personally verify one?
Marc Alexander
CC BY-SA 3.0
2017-04-12T23:34:58.223Z
for a website im working on. I have bitcoinjs library loaded, but not sure what function to call to check if a btc address is valid or not.
Patoshi パトシ
<bitcoinjs><validation>
How do you validate a bitcoin address using bitcoinjs library in javascript?
Patoshi パトシ
# How do you validate a bitcoin address using bitcoinjs library in javascript?

(Asked by: username_0 on 2017-04-12)

How would one validate a bitcoin address using the bitcoinjs library? Or is there another way to do this via javascript?

**Tags:** bitcoinjs, validation

> **Comments:**
> **username_1**: Do you mean for a website or app? Or do you just want to personally verify one?  
> **username_0**: for a website im working on. I have bitcoinjs library loaded, but not sure what function to call to check if a btc address is valid or not.  

---

## 1 answers

### Answer by username_2 on 2017-04-12. Score: 9 | Accepted answer

If you call
bitcoin.address.toOutputScript(address, bitcoin.networks.bitcoin)

It will throw an error if the address cannot be parsed as P2SH or P2PKH, or if the checksum is not valid. Replace the second argument with bitcoin.networks.testnet for testnet.


---

