@inkline/inkline
Version:
Inkline is the intuitive UI Components library that gives you a developer-friendly foundation for building high-quality, accessible, and customizable Vue.js 3 Design Systems.
15 lines (14 loc) • 402 B
JavaScript
export const number = (value, options) => {
let regExpString = "\\d+";
if (options.allowNegative) {
regExpString = "[-]?" + regExpString;
}
if (options.allowDecimal) {
regExpString += "([\\.\\,]\\d+)?";
}
const regExp = new RegExp(`^${regExpString}$`);
if (value?.constructor === Array) {
return value.every((v) => regExp.test(v));
}
return regExp.test(String(value));
};