feat: 🚀 订阅功能
This commit is contained in:
9
src/utils/regexp/boxCodeCtn.ts
Normal file
9
src/utils/regexp/boxCodeCtn.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
//只允许输入CTN开头并且CTN后面只能跟数字
|
||||
export const boxCodeCtn = (target: any) => {
|
||||
console.log(target.length);
|
||||
return target.replace(/[^C|c|T|t|N|n]/g, "");
|
||||
if ((target.length === 1 && target !== "c") || target !== "C") {
|
||||
console.log("123232323");
|
||||
return "";
|
||||
}
|
||||
};
|
||||
7
src/utils/regexp/convertSeparators.ts
Normal file
7
src/utils/regexp/convertSeparators.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { cloneDeep } from "lodash-es";
|
||||
|
||||
//将中文逗号(,)和分号(;)替换为英文逗号(,)
|
||||
export const convertSeparators = (str: string) => {
|
||||
let strClone = cloneDeep(str);
|
||||
return strClone.replace(/,/g, ",");
|
||||
};
|
||||
8
src/utils/regexp/index.ts
Normal file
8
src/utils/regexp/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { inputEnterRexg } from "./inputEnterRexg";
|
||||
import { numberRexg } from "./numberRexg";
|
||||
import { productRexg } from "./productRexg";
|
||||
import { integerRexg } from "./integerRexg";
|
||||
import { unitMultipleInputRexg } from "./unitMultipleInputRexg";
|
||||
import { numberRexg1 } from "./numberRexg1";
|
||||
import { numberDecimalSeparatorRexg } from "./numberDecimalSeparatorRexg";
|
||||
export { numberRexg, inputEnterRexg, productRexg, integerRexg, unitMultipleInputRexg, numberRexg1, numberDecimalSeparatorRexg };
|
||||
26
src/utils/regexp/inputEnterRexg.ts
Normal file
26
src/utils/regexp/inputEnterRexg.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { useMsg } from "@/hooks/useMsg";
|
||||
//只允许输入数字和6位小数
|
||||
export const inputEnterRexg = function (inputValue: any, empty?: any) {
|
||||
inputValue = inputValue.replace(/[^\d.]/g, ""); // 清除"数字"和"."以外的字符 只能输入数字和小数点
|
||||
inputValue = inputValue.replace(/\.{2,}/g, "."); // 不能连续输入两个及以上小数点
|
||||
inputValue = inputValue.replace(".", "$#$").replace(/\./g, "").replace("$#$", "."); // 只保留第一个".", 清除多余的"."
|
||||
inputValue = inputValue.replace(/^(-)*(\d+)\.(\d\d\d\d\d\d).*$/, "$1$2.$3"); // 只能输入六位小数
|
||||
if (inputValue && inputValue.indexOf(".") < 0 && inputValue != "") {
|
||||
inputValue = parseFloat(inputValue);
|
||||
inputValue = inputValue + "";
|
||||
inputValue = inputValue.slice(0, 8);
|
||||
} // 如果没有小数点,首位不能为类似于 01、02的值
|
||||
// 输入过程中,只能输入六位小数且六位小数都为零,则清空小数点和后面的六个零(如果输入完成了只输入四个零,则在blur事件中处理)
|
||||
if (inputValue.indexOf(".") > 0 && inputValue.length - inputValue.indexOf(".") > 6) {
|
||||
let str = inputValue.slice(inputValue.indexOf("."), inputValue.length);
|
||||
if (str / 1 <= 0) {
|
||||
inputValue = inputValue.replace(str, "");
|
||||
}
|
||||
}
|
||||
if (inputValue.length > 15) {
|
||||
useMsg("warning", "仅限数字输入,小数点后最多6位,小数点前最多8位,请重新输入");
|
||||
return empty ? "" : 0;
|
||||
} else {
|
||||
return inputValue;
|
||||
}
|
||||
};
|
||||
3
src/utils/regexp/integer.ts
Normal file
3
src/utils/regexp/integer.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const integer = (target: any) => {
|
||||
return target.replace(/[^1-9]/g, "");
|
||||
};
|
||||
6
src/utils/regexp/integerNumber.ts
Normal file
6
src/utils/regexp/integerNumber.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export const integerNumber = (target: any) => {
|
||||
if (!target) {
|
||||
return target;
|
||||
}
|
||||
return target.replace(/[^0-9]/g, "");
|
||||
};
|
||||
8
src/utils/regexp/integerRexg.ts
Normal file
8
src/utils/regexp/integerRexg.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
//只允许输入整数
|
||||
export const integerRexg = (value: any) => {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
let result = value.replace(/^(0+)|[^\d]+/g, "");
|
||||
return result;
|
||||
};
|
||||
11
src/utils/regexp/numberDecimalSeparatorRexg.ts
Normal file
11
src/utils/regexp/numberDecimalSeparatorRexg.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
//只允许输入数字和小数点
|
||||
export const numberDecimalSeparatorRexg = (value: any) => {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
value = value.replace(/[^\d.]/g, ""); // 清除"数字"和"."以外的字符 只能输入数字和小数点
|
||||
value = value.replace(/\.{2,}/g, "."); // 不能连续输入两个及以上小数点
|
||||
value = value.replace(".", "$#$").replace(/\./g, "").replace("$#$", "."); // 只保留第一个".", 清除多余的"."
|
||||
return value;
|
||||
};
|
||||
18
src/utils/regexp/numberRexg.ts
Normal file
18
src/utils/regexp/numberRexg.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
// 数字验证,小数点前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 "";
|
||||
}
|
||||
};
|
||||
17
src/utils/regexp/numberRexg1.ts
Normal file
17
src/utils/regexp/numberRexg1.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
//前3后4
|
||||
export const numberRexg1 = (value: any) => {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
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 > 3) {
|
||||
let newValue = value_after.toString().substring(0, 3) + "." + value_before;
|
||||
return (newValue.toString().match(/\d{1,3}(\.\d{0,4})?/) || [""])[0];
|
||||
} else {
|
||||
return (value.toString().match(/\d{1,3}(\.\d{0,4})?/) || [""])[0];
|
||||
}
|
||||
}
|
||||
return (value.toString().match(/\d{1,3}(\.\d{0,4})?/) || [""])[0];
|
||||
};
|
||||
17
src/utils/regexp/productRexg.ts
Normal file
17
src/utils/regexp/productRexg.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
//尺寸/质量信息输入验证
|
||||
export const productRexg = (value: any) => {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
let result = value
|
||||
.toString()
|
||||
.replace(/^0/)
|
||||
.replace(/[^\d.]/g, "")
|
||||
.replace(/\.{2,}/g, ".")
|
||||
.replace(/^\./g, "")
|
||||
.replace(".", "$#$")
|
||||
.replace(/\./g, "")
|
||||
.replace("$#$", ".")
|
||||
.replace(/^(-)*(\d+)\.(\d\d\d\d).*$/, "$1$2.$3");
|
||||
return result;
|
||||
};
|
||||
9
src/utils/regexp/removeSpaces.ts
Normal file
9
src/utils/regexp/removeSpaces.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { cloneDeep } from "lodash-es";
|
||||
//去除所有空格
|
||||
export const removeSpaces = (str: any) => {
|
||||
let strClone = cloneDeep(str);
|
||||
if (Array.isArray(strClone) && strClone.length) {
|
||||
strClone = strClone.join("");
|
||||
}
|
||||
return strClone.replace(/\s+/g, "");
|
||||
};
|
||||
13
src/utils/regexp/unitMultipleInputRexg.ts
Normal file
13
src/utils/regexp/unitMultipleInputRexg.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export const unitMultipleInputRexg = (value: any) => {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
let result = value
|
||||
.toString()
|
||||
.replace(/[^\d^\\.]+/g, "")
|
||||
.replace(".", "$#$")
|
||||
.replace(/\./g, "")
|
||||
.replace("$#$", ".")
|
||||
.replace(/^(\\-)*(\d+)\.(\d\d\d\d\d\d\d\d).*$/, "$1$2.$3");
|
||||
return result;
|
||||
};
|
||||
Reference in New Issue
Block a user