|
|
@@ -257,14 +257,32 @@ const onSubmit = async () => {
|
|
|
uni.showToast({ title: '请输入姓名', icon: 'none' })
|
|
|
return
|
|
|
}
|
|
|
+ // 姓名格式校验:2-30 个中文、字母、·或空格
|
|
|
+ const nameRegex = /^[\u4e00-\u9fa5A-Za-z·\s]{2,10}$/
|
|
|
+ if (!nameRegex.test(String(form.value.nickname))) {
|
|
|
+ uni.showToast({ title: '姓名格式不正确,请输入2-10位中文或字母', icon: 'none' })
|
|
|
+ return
|
|
|
+ }
|
|
|
if (!form.value.phone) {
|
|
|
uni.showToast({ title: '请输入手机号', icon: 'none' })
|
|
|
return
|
|
|
}
|
|
|
+ // 手机号格式(中国)校验
|
|
|
+ const phoneRegex = /^1[3-9]\d{9}$/
|
|
|
+ if (!phoneRegex.test(String(form.value.phone))) {
|
|
|
+ uni.showToast({ title: '手机号格式不正确', icon: 'none' })
|
|
|
+ return
|
|
|
+ }
|
|
|
if (!form.value.age) {
|
|
|
uni.showToast({ title: '请输入年龄', icon: 'none' })
|
|
|
return
|
|
|
}
|
|
|
+ // 年龄为 1-120 的整数
|
|
|
+ const ageNum = Number(form.value.age)
|
|
|
+ if (!Number.isInteger(ageNum) || ageNum < 1 || ageNum > 120) {
|
|
|
+ uni.showToast({ title: '年龄请输入1到120之间的整数', icon: 'none' })
|
|
|
+ return
|
|
|
+ }
|
|
|
if (!form.value.sex) {
|
|
|
uni.showToast({ title: '请选择性别', icon: 'none' })
|
|
|
return
|