Skip to content

NoriSte/bitcoin-address-soft-regex-validation

Repository files navigation

bitcoin-address-soft-regex-validation

Build Status Build Cron Renovate enabled Coverage Status Mutation testing badge Maintainability TypeScript

Performs a soft (syntactically-only) validation of Bitcoin address (both Base58 and Bech32, both Mainnet and Testnet). It takes for granted that you have a stronger (maybe server side) Checksum validation.

npm install --save bitcoin-address-soft-regex-validation
const {isValidBitcoinAddress} = require("bitcoin-address-soft-regex-validation");
// a mainnet address
isValidBitcoinAddress("1JDknRvZTi5XdhQB3cgvJ9R8aogUvfbYUB"); // "mainnet"
// a testnet address
isValidBitcoinAddress("tb1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"); // "testnet"
// an invalid address
isValidBitcoinAddress("fake-address"); // undefined

Remember that it's not so important if some false positives pass the validation (as said above, it takes for granted that a serious validation is made elsewhere), the only important thing is that no one valid address is blocked.

It's bases on some resources like this one, this one and mixed together on Regex101.

It has no dependencies and it's a single-function package, check the index.js file to copy the code and avoid adding one more dependency if you want.

Last but not least: it's written in TypeScript.

Contributors

Thanks goes to these wonderful people (emoji key):

Stefano Magni
Stefano Magni

💻 ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!