14

For people that want to do a simple verification of a Monero address to ensure it has been entered correctly, what are some methods that can be employed?

254123179
  • 4,586
  • 4
  • 32
  • 58
ferretinjapan
  • 6,494
  • 2
  • 20
  • 47

5 Answers5

12

Here is a simple regular expression and javascript code snippet that can be used to confirm a Monero address has been entered correctly.

Regular expression:

4[0-9AB][<insert-all-base-58-characters-here>]{93}

In Javascript:

addr_str.match(/4[0-9AB][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{93}/);

Credit goes to /u/binaryfate for the useful info.

ferretinjapan
  • 6,494
  • 2
  • 20
  • 47
2

There are some inappropriate regexes to the other answers here. At this time, only ferretinjapan's answer is correct, though it's a mouthful since it does not use ranges.

This regex will match (non-integrated) Monero addresses (subaddresses start with 8):

^[48][0-9AB][1-9A-HJ-NP-Za-km-z]{93}$

An integrated address has 106 or 136 characters and that the second character may be any base58 character (verification needed; this is a result of changing the netbyte prefix). Here's a regex to match just integrated (either 64-bit or full 256-bit) addresses:

^4[1-9A-HJ-NP-Za-km-z]{105}(?:[1-9A-HJ-NP-Za-km-z]{30})?$

To match any Monero address (standard, subaddress, integrated, or full 256-bit integrated):

^(?:[48][0-9AB]|4[1-9A-HJ-NP-Za-km-z]{12}(?:[1-9A-HJ-NP-Za-km-z]{30})?)[1-9A-HJ-NP-Za-km-z]{93}$

With any of these regexes, if you are extracting addresses from larger bodies of text, you likely want to replace the ^ and $ anchors with \b word boundary markers.

Adam Katz
  • 121
  • 4
2

This is better:

4[a-zA-Z|\d]{94}

And payment ID:

[0-9a-fA-F]{64} 
Asdax
  • 551
  • 4
  • 12
0

My Java Example:

public static boolean MoneroValid(String addr)
{
    String regex = "^4[0-9AB][1-9A-HJ-NP-Za-km-z]{93}$";
    return addr.matches(regex);
}
jtgrassie
  • 19,601
  • 4
  • 17
  • 54
0

Long time ago someone pointed to me this regex to address

/4([0-9]|[A-B])(.){93}/

I belive its an more complete one, I am using it on PHP-Monero

Pedro Gaspar
  • 635
  • 3
  • 7