Browse Source

增添邮箱验证规则

wangyi/feature-20251022162725-启动页登录注册
Ethereal 4 weeks ago
parent
commit
c3d7906515
  1. 69
      pages/start/login/login.vue
  2. 12
      pages/start/login/verification.js

69
pages/start/login/login.vue

@ -240,7 +240,7 @@ import countryList from "./list.js";
import footerBar from "../../../components/footerBar-cn"; import footerBar from "../../../components/footerBar-cn";
import uniPopupDialogVue from "../../../uni_modules/uni-popup/components/uni-popup-dialog/uni-popup-dialog.vue"; import uniPopupDialogVue from "../../../uni_modules/uni-popup/components/uni-popup-dialog/uni-popup-dialog.vue";
import uniPopup from "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.vue"; import uniPopup from "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.vue";
import {verification} from "../login/verification"
import { verificationPhone, verificationEmail } from "../login/verification";
const deepChartID = ref(""); const deepChartID = ref("");
const type = ref("member"); const type = ref("member");
@ -268,7 +268,8 @@ const countries = ref(
// //
const selectedCountry = ref( const selectedCountry = ref(
countries.value.find((country) => country.short === "CN") || countries.value[0]
countries.value.find((country) => country.short === "CN") ||
countries.value[0]
); );
// //
@ -279,7 +280,7 @@ function showCountryPicker() {
), ),
success: function (res) { success: function (res) {
selectedCountry.value = countries.value[res.tapIndex]; selectedCountry.value = countries.value[res.tapIndex];
country.value = selectedCountry.value.code
country.value = selectedCountry.value.code;
}, },
}); });
} }
@ -301,14 +302,12 @@ function switchEmail() {
// //
switchType.value = "Email"; switchType.value = "Email";
password.value = ""; password.value = "";
} }
function switchPhone() { function switchPhone() {
// //
switchType.value = "Phone"; switchType.value = "Phone";
password.value = ""; password.value = "";
} }
function register() { function register() {
@ -330,7 +329,6 @@ function register() {
} }
} }
if (switchType.value === "Phone") { if (switchType.value === "Phone") {
// //
if (!phone.value) { if (!phone.value) {
@ -348,22 +346,16 @@ function register() {
}); });
return; return;
} }
const phoneAll = `${country.value}${phone.value}`
const phoneAll = `${country.value}${phone.value}`;
console.log("完整手机号" + phoneAll); console.log("完整手机号" + phoneAll);
if (validatePhoneNumber(country.value, phone.value)) { if (validatePhoneNumber(country.value, phone.value)) {
console.log("登录成功:", phoneAll); console.log("登录成功:", phoneAll);
} }
// //
// console.log(":", phone.value); // console.log(":", phone.value);
} }
if (switchType.value === "Email") { if (switchType.value === "Email") {
// //
if (!email.value) { if (!email.value) {
@ -382,6 +374,18 @@ function register() {
return; return;
} }
const bool = verificationEmail(email.value);
console.log("验证是否成功", bool);
//
if (!bool) {
uni.showToast({
title: "邮箱格式不正确",
icon: "none",
});
return;
}
// //
console.log("登录:", email.value); console.log("登录:", email.value);
} }
@ -483,6 +487,18 @@ function sendCode() {
}); });
return; return;
} }
const bool = verificationPhone(country.value, phone.value);
console.log("验证是否成功", bool);
//
if (!bool) {
uni.showToast({
title: "手机号格式不正确",
icon: "none",
});
return;
}
} }
if (switchType.value === "Email") { if (switchType.value === "Email") {
@ -493,9 +509,18 @@ function sendCode() {
}); });
return; return;
} }
}
const bool = verificationEmail(email.value);
console.log("验证是否成功", bool);
//
if (!bool) {
uni.showToast({
title: "邮箱格式不正确",
icon: "none",
});
return;
}
}
// //
if (isCodeBtnDisabled.value) return; if (isCodeBtnDisabled.value) return;
@ -549,7 +574,7 @@ function changeCheckbox() {
// //
function validatePhoneNumber(countryCode, phoneNumber) { function validatePhoneNumber(countryCode, phoneNumber) {
// //
if (!phoneNumber || phoneNumber.trim() === '') {
if (!phoneNumber || phoneNumber.trim() === "") {
uni.showToast({ uni.showToast({
title: "手机号不能为空", title: "手机号不能为空",
icon: "none", icon: "none",
@ -557,8 +582,7 @@ function validatePhoneNumber(countryCode, phoneNumber) {
return false; return false;
} }
const bool = verification(countryCode,phoneNumber)
const bool = verificationPhone(countryCode, phoneNumber);
console.log("验证是否成功", bool); console.log("验证是否成功", bool);
// //
@ -571,7 +595,7 @@ function validatePhoneNumber(countryCode, phoneNumber) {
} }
// +715 // +715
const cleanNumber = phoneNumber.replace(/^\+/, '');
const cleanNumber = phoneNumber.replace(/^\+/, "");
if (cleanNumber.length < 7 || cleanNumber.length > 15) { if (cleanNumber.length < 7 || cleanNumber.length > 15) {
uni.showToast({ uni.showToast({
title: "手机号长度不正确", title: "手机号长度不正确",
@ -582,13 +606,6 @@ function validatePhoneNumber(countryCode, phoneNumber) {
return true; return true;
} }
//
</script> </script>
<style scoped> <style scoped>

12
pages/start/login/verification.js

@ -1,5 +1,5 @@
function verification(countryCode,phoneNumber) {
function verificationPhone(countryCode,phoneNumber) {
switch (countryCode) { switch (countryCode) {
case '+86': case '+86':
return verificationChina(phoneNumber); return verificationChina(phoneNumber);
@ -58,4 +58,12 @@ function verificationVietnam(phoneNumber){
return phoneRegex.test(phoneNumber); return phoneRegex.test(phoneNumber);
} }
export {verification}
function verificationEmail(email) {
const emailRegex = /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/;
return emailRegex.test(email);
}
export {verificationPhone,verificationEmail}
Loading…
Cancel
Save