Just wondering if anyone can help me preg_match a Stellar public address in PHP?
1 Answer
A stellar address begins with "G", followed by "[A-D]" and then 54 characters from this base32 alphabet "[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]", so:
preg_match('/^G[ABCD]{1}[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]{54}$/', $s);
However you could also use this php sdk like this:
try {
$key = \ZuluCrypto\StellarSdk\Keypair::newFromPublicKey($s);
} catch (Exception $e) {
exit('Invalid Address: ' . $s);
}