Post
Topic
Board Development & Technical Discussion
Merits 3 from 3 users
Re: Regex for Testnet WIF [solved]
by
pooya87
on 13/07/2021, 02:29:39 UTC
⭐ Merited by NotATether (1) ,ETFbitcoin (1) ,naufragus (1)
a function to validate Testnet WIF ,
This is not how you should "validate" a WIF though. The string length and starting character are not important to the code (only for readability).

What you should do is decode the string using Base58check (validates its checksum too) then check the byte array result:
- Length: 33 byte long for uncompressed, 34 byte long compressed
- First byte: based on network type eg. 239 for regtest
- Last byte: only for compressed that must be 1
- Remaining 32 byte: that must be between 1 and N-1 inclusive