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 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 {verification} from "../login/verification"
import { verificationPhone, verificationEmail } from "../login/verification";
const deepChartID = ref("");
const type = ref("member");
@ -268,7 +268,8 @@ const countries = 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) {
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";
password.value = "";
}
function switchPhone() {
//
switchType.value = "Phone";
password.value = "";
}
function register() {
@ -330,7 +329,6 @@ function register() {
}
}
if (switchType.value === "Phone") {
//
if (!phone.value) {
@ -348,22 +346,16 @@ function register() {
});
return;
}
const phoneAll = `${country.value}${phone.value}`
const phoneAll = `${country.value}${phone.value}`;
console.log("完整手机号" + phoneAll);
if (validatePhoneNumber(country.value, phone.value)) {
console.log("登录成功:", phoneAll);
}
//
// console.log(":", phone.value);
}
if (switchType.value === "Email") {
//
if (!email.value) {
@ -382,6 +374,18 @@ function register() {
return;
}
const bool = verificationEmail(email.value);
console.log("验证是否成功", bool);
//
if (!bool) {
uni.showToast({
title: "邮箱格式不正确",
icon: "none",
});
return;
}
//
console.log("登录:", email.value);
}
@ -483,6 +487,18 @@ function sendCode() {
});
return;
}
const bool = verificationPhone(country.value, phone.value);
console.log("验证是否成功", bool);
//
if (!bool) {
uni.showToast({
title: "手机号格式不正确",
icon: "none",
});
return;
}
}
if (switchType.value === "Email") {
@ -493,9 +509,18 @@ function sendCode() {
});
return;
}
}
const bool = verificationEmail(email.value);
console.log("验证是否成功", bool);
//
if (!bool) {
uni.showToast({
title: "邮箱格式不正确",
icon: "none",
});
return;
}
}
//
if (isCodeBtnDisabled.value) return;
@ -549,7 +574,7 @@ function changeCheckbox() {
//
function validatePhoneNumber(countryCode, phoneNumber) {
//
if (!phoneNumber || phoneNumber.trim() === '') {
if (!phoneNumber || phoneNumber.trim() === "") {
uni.showToast({
title: "手机号不能为空",
icon: "none",
@ -557,8 +582,7 @@ function validatePhoneNumber(countryCode, phoneNumber) {
return false;
}
const bool = verification(countryCode,phoneNumber)
const bool = verificationPhone(countryCode, phoneNumber);
console.log("验证是否成功", bool);
//
@ -571,7 +595,7 @@ function validatePhoneNumber(countryCode, phoneNumber) {
}
// +715
const cleanNumber = phoneNumber.replace(/^\+/, '');
const cleanNumber = phoneNumber.replace(/^\+/, "");
if (cleanNumber.length < 7 || cleanNumber.length > 15) {
uni.showToast({
title: "手机号长度不正确",
@ -582,13 +606,6 @@ function validatePhoneNumber(countryCode, phoneNumber) {
return true;
}
//
</script>
<style scoped>

12
pages/start/login/verification.js

@ -1,5 +1,5 @@
function verification(countryCode,phoneNumber) {
function verificationPhone(countryCode,phoneNumber) {
switch (countryCode) {
case '+86':
return verificationChina(phoneNumber);
@ -58,4 +58,12 @@ function verificationVietnam(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