@daimo/pay
Version:
Seamless crypto payments. Onboard users from any chain, any coin into your app with one click.
17 lines (15 loc) • 549 B
JavaScript
function isValidNumber(value, maxDecimals) {
if (value.length === 0) {
return false;
}
const match = /^\d*\.?(\d*)$/.exec(value);
if (match == null) return false;
return maxDecimals == null || match[1].length <= maxDecimals;
}
function sanitizeNumber(value) {
const cleaned = value.replace(/[^0-9.]/g, "");
if (!cleaned || cleaned === "." || !/^\d*\.?\d*$/.test(cleaned)) return "0";
return cleaned.startsWith(".") ? `0${cleaned}` : cleaned;
}
export { isValidNumber, sanitizeNumber };
//# sourceMappingURL=validateInput.js.map