Search code examples
c#bitcoin

C# Bitcoin Address Validation [Legacy, Nested SegWit, Native SegWit] | OFFLINE


I am looking for a class or method in c# language to validate bitcoin address.(OFFLINE)
I want to validate [Legacy, Nested SegWit, Native SegWit] address types.

For this purpose i found this :
determine-if-a-bitcoin-wallet-address-is-valid
But it validates Legacy addresses only.

I also found this :
bitcoin-address-validation
But i think it is using an api for this purpose & language is not c#.

I also found this :
bitcoin-address-validator
This is not in c# language. It's php & i am not familiar with php.

I also found this :
address_validation
Too old and only for Legacy addresses.

Please give me a solution on this.


Determine type of bitcoin address is not important for me.
I just want to know that a string is bitcoin address or not.


Solution

  • Correct Regex :

    string re_path = @"^(?:[13]{1}[a-km-zA-HJ-NP-Z1-9]{25,34}|bc1[a-z0-9]{39,59})$";
    

    Source :
    Regex for Bitcoin Addresses
    Attention :
    Address length in Base58 is not fixed. It may be as small as 26 and as big as 35 (the other answer uses wrong values)
    So i corrected it in this answer

    Test :
    Regex-Test