[Solved] Pub Key/Address Regex - Advice on regular expressions Valid FTC keys
-
In the process of writing a mobile application and wanted to check on the validity of FTC addresses without hitting the network each time (seems unnecessary when just adding new addresses from a barcode).
I’ve adapted a regex someone posted for LTC some for what I _think_ is valid for FTC. Can anyone confirm the following:
Rules:
- Always starts with the #6
- 34 characters long (in total)
- a-z, A-Z, 0-9 are the only valid characters allowed.
- Ends with a capital character (A-Z)
If so, I believe the regex would be the following:
- ^6[a-zA-Z0-9]{32}[A-Z]{1}$
Can anyone confirm the above?
Thanks!
Joel -
No. Some start with 7.
-
[quote name=“Mathco” post=“46484” timestamp=“1387554970”]
In the process of writing a mobile application and wanted to check on the validity of FTC addresses without hitting the network each time (seems unnecessary when just adding new addresses from a barcode).I’ve adapted a regex someone posted for LTC some for what I _think_ is valid for FTC. Can anyone confirm the following:
Rules:
- Always starts with the #6
- 34 characters long (in total)
- a-z, A-Z, 0-9 are the only valid characters allowed.
- Ends with a capital character (A-Z)
If so, I believe the regex would be the following:
- ^6[a-zA-Z0-9]{32}[A-Z]{1}$
Can anyone confirm the above?
Thanks!
Joel
[/quote]Nope. Some start with 6, some start with 7. lowercase l is not allowed, nor is uppercase I or uppercase O, or 0.
Here’s the list.
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
But even then it can still be an invalid address.
What you need to do is base58 decode it, then strip the last 4 bytes, and run that through 2 rounds of sha256. If the first 4 bytes of that has match the last 4 bytes you stripped off previously, it’s a valid address.
-
Great information. Thanks!
That means if I use the Regular Expression method (as a dummy check at least for now) the expression would be something like the following:
^[6-7][ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz1-9]{33}$
I’ll look into the Base58/SHA256 way later on when I get encryption libraries included though.
Thanks again!