33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
// ? Element 常用表单校验规则
|
|
|
|
/**
|
|
* @rule 手机号
|
|
*/
|
|
export function checkPhoneNumber(rule: any, value: any, callback: any) {
|
|
const regexp = /^(((13[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(17[3-8]{1})|(18[0-9]{1})|(19[0-9]{1})|(14[5-7]{1}))+\d{8})$/;
|
|
if (value === "") callback("请输入手机号码");
|
|
if (!regexp.test(value)) {
|
|
callback(new Error("请输入正确的手机号码"));
|
|
} else {
|
|
return callback();
|
|
}
|
|
}
|
|
|
|
export function numberRexgu(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,6})?/) || [""])[0];
|
|
} else {
|
|
return (value.toString().match(/\d{1,8}(\.\d{0,6})?/) || [""])[0];
|
|
}
|
|
}
|
|
return (value.toString().match(/\d{1,8}(\.\d{0,6})?/) || [""])[0];
|
|
} else {
|
|
return "";
|
|
}
|
|
}
|