mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-23 09:52:57 +08:00
15 lines
343 B
TypeScript
15 lines
343 B
TypeScript
export function formatNumber(value: string, allowDot: boolean) {
|
|
if (allowDot) {
|
|
const dotIndex = value.indexOf('.');
|
|
|
|
if (dotIndex > -1) {
|
|
value =
|
|
value.slice(0, dotIndex + 1) + value.slice(dotIndex).replace(/\./g, '');
|
|
}
|
|
}
|
|
|
|
const regExp = allowDot ? /[^0-9.]/g : /\D/g;
|
|
|
|
return value.replace(regExp, '');
|
|
}
|