Files
orico-wms-ts-admin/src/hooks/useValidateInput.ts

16 lines
597 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.

import { cloneDeep } from "lodash-es";
//只能输入数字和小数点否则为0
export const useValidateInput = (value: any) => {
let valueClone = cloneDeep(value) + "";
//只能输入1-9和小数点并且第一位不能为小数点
let replaceValue = valueClone
.replace(/^\.+/g, "0.")
.replace(/[^\d^\\.]+/g, "")
.replace(".", "$#$")
.replace(/\./g, "")
.replace("$#$", ".");
//禁止输入多个小数点
let resultValue = replaceValue.replace(/^(\\-)*(\d+)\.(\d\d\d\d\d\d\d\d\d\d).*$/, "$1$2.$3");
return resultValue;
};