I made an app that returns user assets from the Aptos blockchain. In the app, I have a form for the user's address. My goal is to validate that address using RegExp or something like that. I have this code:
const address = '0xcd30fbbda98b2aed026772c13e5ed90a7f056b589ef9e78cd96415e1af12451c';
function isValidAddress(address) { // code to check address }
console.log(isValidAddress(address));
I will appreciate any help.
It depends on your use case.
If you want to validate client side, you can try something like this:
AccountAddress
: https://aptos-labs.github.io/ts-sdk-doc/classes/TxnBuilderTypes.AccountAddress.html.You can also try to validate using an Aptos node running the API (i.e. a fullnode). For example:
If the account exists, you'll get a 200 or if it doesn't, you'll get a 404. But if the account address was invalid, you'll get a 400 (bad request).
getAccount
: https://aptos-labs.github.io/ts-sdk-doc/classes/AptosClient.html#getAccount.