From fde16ed45c5236fddb853d41767d17a649bb8bdd Mon Sep 17 00:00:00 2001 From: zhouxueli <2841188632@qq.com> Date: Thu, 22 Jan 2026 16:57:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=95=86=E4=BA=BA=E5=91=98?= =?UTF-8?q?=EF=BC=8C=E7=94=B5=E8=AF=9D=E6=A0=BC=E5=BC=8F=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E8=A7=84=E5=88=99=E5=90=8C=E6=AD=A5=E7=B3=BB=E7=BB=9F=E5=90=8E?= =?UTF-8?q?=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/mine/personList.vue | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/views/mine/personList.vue b/src/views/mine/personList.vue index dc8c2d73..53585e20 100644 --- a/src/views/mine/personList.vue +++ b/src/views/mine/personList.vue @@ -121,7 +121,7 @@ export default { let flag=this.validatePhone(val) // console.log('flag',flag) if(!flag){ - this.$toast('手机号格式不正确') + this.$toast('电话号码格式不正确') } }, validatePhone(val) { @@ -129,13 +129,22 @@ export default { if(!val){ return true } - const purePhone = val - // 情况1:11位且1开头 → 合法 - if (/^1[0-9]{10}$/.test(purePhone)) { + const purePhone = String(val).trim() + const mobileReg = /^1[3-9]\d{9}$/ // 大陆手机号正则表达式 + const hkMobileReg = /^[569]\d{3}[\s-]?\d{4}$/ // 香港手机号正则表达式,允许使用空格或 "-" 分隔 + const macauMobileReg = /^6\d{3}[\s-]?\d{4}$/ // 澳门手机号正则表达式,允许使用空格或 "-" 分隔 + const telReg = /^(0\d{2,3})([\s-])?\d{7,8}$/ // 大陆座机号正则表达式,允许区号和座机号用空格或 "-" 分开 + const hkTelReg = /^\(?\d{2,4}\)?[\s-]?\d{4}[\s-]?\d{4}$/ // 香港座机号正则表达式,允许使用空格或 "-" 分隔 + const macauTelReg = /^\(?\d{2,4}\)?[\s-]?\d{4}[\s-]?\d{4}$/ // 澳门座机号正则表达式,允许使用空格或 "-" 分隔 + const phone400Reg = /^400[\s-]?\d{3}[\s-]?\d{4}$/ // 以 "400" 开头的号码正则表达式,允许使用空格或 "-" 分隔 + // 情况1:12位且首位是0、第二位是1 → 去0后按大陆手机号校验 + if (/^01[0-9]{10}$/.test(purePhone)) { return true } - // 情况2:12位且首位是0、第二位是1 → 去0后合法 - if (/^01[0-9]{10}$/.test(purePhone)) { + // 匹配任意一种格式即为合法 + if (mobileReg.test(purePhone) || hkMobileReg.test(purePhone) || macauMobileReg.test(purePhone) || + telReg.test(purePhone) || hkTelReg.test(purePhone) || macauTelReg.test(purePhone) || + phone400Reg.test(purePhone)) { return true } // 其他情况 → 不合法 @@ -226,6 +235,7 @@ export default { console.log('phone1Flag',phone1Flag) console.log('phone2Flag',phone2Flag) if(!phone1Flag || !phone2Flag){ + this.$toast('电话号码格式不正确') return } await submitConfirm({supplierId:this.supplierId,infos:this.personList})