Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to properly validate if any string is a valid bitcoin address? #246

Open
djalfirevic opened this issue Mar 7, 2020 · 1 comment
Open

Comments

@djalfirevic
Copy link

Is there any method where you can post a string, and that it returns whether this is a valid address or not?

I've tried to use something like this

private func isValidAddress() -> Bool {
    if let _ = try? BitcoinAddress(cashaddr: address) {
        return true
    } else if let _ = try? BitcoinAddress(legacy: address) {
        return true
    }
        
    return true
}
@SwenVanZanten
Copy link

Thats actually the correct way of validating an address.
Only I would change the last return and actually pass the address 😜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants