Files
orico-officialWebsite-ts-admin/src/utils/regexp/numberRexg.ts
2025-03-26 11:00:21 +08:00

19 lines
797 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 数字验证小数点前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 "";
}
};