19 lines
797 B
TypeScript
19 lines
797 B
TypeScript
// 数字验证,小数点前8位&小数点后4位
|
||
export const numberRexg = (value: any) => {
|
||
if (value) {
|
||
if (value.toString().indexOf(".") != -1) {
|
||
let value_after = parseInt(value.toString().substring(0, value.indexOf(".")));
|
||
let value_before = value.replace(/\d+\.(\d*)/, "$1");
|
||
if (value_after.toString().length > 8) {
|
||
let newValue = value_after.toString().substring(0, 8) + "." + value_before;
|
||
return (newValue.toString().match(/\d{1,8}(\.\d{0,4})?/) || [""])[0];
|
||
} else {
|
||
return (value.toString().match(/\d{1,8}(\.\d{0,4})?/) || [""])[0];
|
||
}
|
||
}
|
||
return (value.toString().match(/\d{1,8}(\.\d{0,4})?/) || [""])[0];
|
||
} else {
|
||
return "";
|
||
}
|
||
};
|