vue 之手机号验证、正则验证手机号是否正确
项目介绍:
首先 项目是为了获取用户手机号码,其次 验证手机号后才可评论也是为了不让用户乱评论;
2.
填写评论后,弹出提交手机号、验证码弹窗;填写手机号后获取验证码,输入验证码正确后,才可提交评论;
// 1.判断评论内容不为空,出验证手机号弹窗;
posttijiao () {
if (this.plcontent == "") {
Message({
message: "评论不能为空",
type: "warning",
duration: 5 * 1000
});
} else if (this.lpdptel == "") {
this.islpdp = true;
//this.tiptan(4);
}
},
//1.验证手机号 正则判断为正确的手机号才发送验证请求;
codetap () {
if (!/^1[34578]\d{9}$/.test(this.lpdptel)) {
Message({
message: "请填写正确的手机号",
type: "warning",
duration: 5 * 1000
});
} else {
const params = {
mobile: this.lpdptel
};
sendCode(params).then(res => {
console.log(res);
if (res.msg == "发送成功!") {
Message({
message: "发送成功!",
type: "warning",
duration: 5 * 1000
});
}
});
}
},
//3.最后提交评论 判断手机号正确 验证码不为空 提交评论;
getloupanpinglun () {
if (this.ison) {
if (!/^1[34578]\d{9}$/.test(this.lpdptel)) {
Message({
message: "请填写正确的手机号",
type: "warning",
duration: 5 * 1000
});
} else if (this.code == "") {
Message({
message: "请填写验证码",
type: "warning"