From bb7db62b1663c3b30830e1604731c2197f46af75 Mon Sep 17 00:00:00 2001
From: Your Name <123456>
Date: Wed, 30 Nov 2022 09:18:23 +0800
Subject: [PATCH] 物资
---
src/utils/toolsValidate.ts | 20 ++++++++++++++++++++
1 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/src/utils/toolsValidate.ts b/src/utils/toolsValidate.ts
index 9845b35..434466e 100644
--- a/src/utils/toolsValidate.ts
+++ b/src/utils/toolsValidate.ts
@@ -60,6 +60,26 @@
}
/**
+ * 0到9
+ * @param val 当前值字符串
+ * @returns 返回处理后的字符串
+ */
+export function verifyString(val: string) {
+ let v = val.replace(/(^\s*)|(\s*$)/g, '');
+ // 只能是数字和小数点,不能是其他输入
+ v = v.replace(/[^\d.]/g, '');
+ // 以0开始只能输入一个
+ v = v.replace(/^\./g, '');
+ // 小数只能出现1位
+ v = v.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
+ // 小数点后面保留2位
+ v = v.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
+ // 返回结果
+ return v;
+}
+
+
+/**
* 正整数验证
* @param val 当前值字符串
* @returns 返回处理后的字符串
--
Gitblit v1.9.2