data() {
//手机号验证
var checkPhone = (rule, value, callback) => {
// 手机号验证
if (!value) {
// return callback(new Error("联系电话不能为空"));
} else {
const reg = /^1[3456789]\d{9}$/;
if (reg.test(value)) {
callback();
} else {
return callback(new Error("请输入正确的联系电话"));
}
}
};
//经度验证
var longitude = (rule, value, callback) => {
let isTrue =
/^(\-|\+)?(((\d|[1-9]\d|1[0-7]\d|0{1,3})\.\d{0,6})|(\d|[1-9]\d|1[0-7]\d|0{1,3})|180\.0{0,6}|180)$/;
if (!value) {
} else {
if (!isTrue.test(value)) {
callback(new Error("请按照经度规则输入"));
} else if (value.slice(-1) == ".") {
callback(new Error("最后一位不能是小数点"));
} else {
callback();
}
}
};
//纬度验证
var latitude = (rule, value, callback) => {
let isTrue = /^(\-|\+)?([0-8]?\d{1}\.\d{0,6}|90\.0{0,6}|[0-8]?\d{1}|90)$/;
if (!value) {
} else {
if (!isTrue.test(value)) {
callback(new Error("请按照纬度规则输入"));
} else if (value.slice(-1) == ".") {
callback(new Error("最后一位不能是小数点"));
} else {
callback();
}
}
};
return {
ruleForm: {},
rules: {
telephone: [
{ required: false, validator: checkPhone, trigger: "change" },
],
longitude: [
{ required: false, validator: longitude, trigger: "change" },
],
latitude: [{ required: false, validator: latitude, trigger: "change" }],
},
};
},
elementui中验证经度和纬度、手机号
最新推荐文章于 2024-03-05 15:10:05 发布