XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.21k stars 512 forks source link

Question: Validate Account format #875

Closed AdvancedStyle closed 6 years ago

AdvancedStyle commented 6 years ago

I'm looking for a simple way to validate an account format (without having to connect to a server).

For example something like this (not correct attempt just an example of what I'm trying to do):

const {RippleAPI} = require('ripple-lib');

const api = new RippleAPI();

const account= 'sllfsldfjasdlfjasdflasdfakjldfjkalsdfkjlsadkfjlaskdljf'

try {
    api.validateAccount(account);
    console.log('Account Good');
}catch(error){
    console.log('Address Bad');
}
sublimator commented 6 years ago

Check out ripple-address-codec module. It has is*Valid methods

AdvancedStyle commented 6 years ago

Thanks, here's my final script if anyone else needs it:

const api = require('ripple-address-codec');

const args = process.argv.slice(2);

try {
    const result = api.isValidAccountID(args[0]);
    console.log(JSON.stringify({"success":result}));
}catch(error){
    console.log(JSON.stringify({"success":false, "error":error}));
}