UNPKG

@activecollab/components

Version:

ActiveCollab Components

33 lines 1.28 kB
import { currencyMultiplier } from "./currencyUtils"; export const validateStopwatchTime = value => { return /^([0-9]{0,2})?(((:([0-5][0-9])?)|(:[0-5]?))|(\.[0-9]{0,2})|(,[0-9]{0,2}))?$/g.test(value); }; export const validateTimeInput = (value, withLeadingZero) => { if (withLeadingZero) { return /^(([0-9][0-9]?|[1-9][0-9]{2,8})?(([:,.][0-5][0-9]?)|([:,.][0-5]?)|(\.[0-9]{1,2})|(,[0-9]{1,2}))?)$/.test(value); } else { return /^(([1-9][0-9]*|0)?(([:,.][0-5][0-9]?)|([:,.][0-5]?)|(\.[0-9]{1,2})|(,[0-9]{1,2}))?)$/.test(value); } }; export const validateNumberInput = function (value, disableMacros, decimalSeparator, decimalLength, limit) { if (limit === void 0) { limit = 12; } if (value.startsWith("00")) { return false; } const numericInput = disableMacros ? value : value.replace(/([0-9.]+)([kmbtKMBT])/, (_, num, unit) => { return (parseFloat(num) * currencyMultiplier[unit.toLowerCase()]).toString(); }); const regexString = "^(-?\\d{0," + limit + "}(?:\\" + decimalSeparator + "\\d{0," + decimalLength + "})?)?$"; return new RegExp(regexString).test(numericInput); }; export const isValidUrl = string => { try { new URL(string); return true; } catch (_) { return false; } }; //# sourceMappingURL=validation.js.map