From 1e2593fd3be8eaee91c64c2756fd4d34014f4dac Mon Sep 17 00:00:00 2001 From: chen-xin-zhi <3588068430@qq.com> Date: Tue, 17 Jun 2025 18:17:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=88=86=E6=94=AF=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/loginModule/register/register.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/pages/loginModule/register/register.js b/pages/loginModule/register/register.js index 2aa6998..0f26104 100644 --- a/pages/loginModule/register/register.js +++ b/pages/loginModule/register/register.js @@ -89,6 +89,29 @@ Page({ agree: e.detail.value.length > 0 }); }, + validatePassword(password) { + // 校验密码长度 + if (password.length < 6 || password.length > 10) { + wx.showToast({ + title: '密码长度应在6到10个字符之间', + icon: 'none', + duration: 1000 + }); + return false; + } + + // 校验是否包含字母、数字和下划线 + const regex = /^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z0-9]+$/; + if (!regex.test(password)) { + wx.showToast({ + title: '密码必须包含字母和数字,且不包含特殊字符', + icon: 'none', + duration: 1000 + }); + return false; + } + return true; + }, // 注册按钮点击 async onRegister() { @@ -102,12 +125,13 @@ Page({ })) { return; } + const { nickname, phone, captcha, inviteCode, password } = this.data; + if (!this.validatePassword(password)) return ; // 2. 再单独校验协议勾选 if (!this.data.agree) { wx.showToast({ title: '请先同意用户协议', icon: 'none' }); return; } - const { nickname, phone, captcha, inviteCode, password } = this.data; wx.showLoading({ title: '加载中', mask: true