Browse Source

增添邮箱验证规则

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

107
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) {
@ -341,30 +339,24 @@ function register() {
return;
}
if (!password.value) {
if (!password.value) {
uni.showToast({
title: "请输入验证码",
icon: "none",
});
return;
}
const phoneAll = `${country.value}${phone.value}`
console.log("完整手机号"+phoneAll);
if(validatePhoneNumber(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 (switchType.value === "Email") {
//
if (!email.value) {
uni.showToast({
@ -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);
}
@ -475,27 +479,48 @@ function onPhoneInput(e) {
}
function sendCode() {
if(switchType.value === "Phone"){
if(!phone.value){
if (switchType.value === "Phone") {
if (!phone.value) {
uni.showToast({
title: "请输入手机号",
icon: "none",
});
return;
}
}
if(switchType.value === "Email"){
if(!email.value){
const bool = verificationPhone(country.value, phone.value);
console.log("验证是否成功", bool);
//
if (!bool) {
uni.showToast({
title: "请输入邮箱地址",
title: "手机号格式不正确",
icon: "none",
});
return;
}
}
if (switchType.value === "Email") {
if (!email.value) {
uni.showToast({
title: "请输入邮箱地址",
icon: "none",
});
return;
}
const bool = verificationEmail(email.value);
console.log("验证是否成功", bool);
//
if (!bool) {
uni.showToast({
title: "邮箱格式不正确",
icon: "none",
});
return;
}
}
//
if (isCodeBtnDisabled.value) return;
@ -549,46 +574,38 @@ function changeCheckbox() {
//
function validatePhoneNumber(countryCode, phoneNumber) {
//
if (!phoneNumber || phoneNumber.trim() === '') {
uni.showToast({
title: "手机号不能为空",
icon: "none",
});
if (!phoneNumber || phoneNumber.trim() === "") {
uni.showToast({
title: "手机号不能为空",
icon: "none",
});
return false;
}
const bool = verification(countryCode,phoneNumber)
const bool = verificationPhone(countryCode, phoneNumber);
console.log("验证是否成功", bool);
//
if (!bool) {
uni.showToast({
title: "手机号格式不正确",
icon: "none",
});
uni.showToast({
title: "手机号格式不正确",
icon: "none",
});
return false;
}
// +715
const cleanNumber = phoneNumber.replace(/^\+/, '');
const cleanNumber = phoneNumber.replace(/^\+/, "");
if (cleanNumber.length < 7 || cleanNumber.length > 15) {
uni.showToast({
title: "手机号长度不正确",
icon: "none",
});
title: "手机号长度不正确",
icon: "none",
});
return false;
}
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