mirror of
https://github.com/gosticks/iota.lib.java.git
synced 2026-02-04 15:42:44 +00:00
27 lines
839 B
Java
27 lines
839 B
Java
package jota.utils;
|
|
|
|
/**
|
|
* Created by pinpong on 02.12.16.
|
|
*/
|
|
public class InputValidator {
|
|
|
|
public static boolean isAddress(String address) {
|
|
// TODO: In the future check checksum
|
|
// Check if address with checksum
|
|
return (address.length() == Constants.addressLengthWithoutChecksum ||
|
|
address.length() == Constants.addressLengthWithChecksum) && isTrytes(address, address.length());
|
|
}
|
|
|
|
|
|
public static boolean checkAddress(String address) {
|
|
if (!isAddress(address))
|
|
throw new RuntimeException("Invalid address: " + address);
|
|
return true;
|
|
}
|
|
|
|
public static boolean isTrytes(String trytes, int length) {
|
|
// If no length specified, just validate the trytes
|
|
return trytes.matches("^[9A-Z]{" + (length == 0 ? "0," : length) + "}$");
|
|
}
|
|
}
|