feat(Field): add digit type (#5524)

This commit is contained in:
neverland
2020-01-09 15:28:58 +08:00
committed by GitHub
parent 47e326fb2a
commit ac3808cd47
7 changed files with 113 additions and 45 deletions
+14
View File
@@ -0,0 +1,14 @@
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, '');
}