1:獲取驗證碼的方法
1:template:
<div>
<div class="title-bo">
驗證碼
</div>
<input type="text" placeholder="請輸入短信驗證碼" class="inputText" v-model="code">
</div>
<div>
<van-button class="alin-btn color" :disabled="disabled" @click="sendcode">
{{codetext}}
</van-button>
</div>
2:data:
data() {
return {
time: 60,
codetext: "獲取驗證碼",
disabled: false,
}
},
methods:{
//既能驗證手機號 也能驗證郵箱
sendcode() {
let mobileReg = /^1(3|4|5|7|8|9)\d{9}$/;
let emailReg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
if (!this.account) {
this.$toast('請輸入手機號或郵箱'); // 請輸入手機號或郵箱
} else if (!mobileReg.test(this.account) && !emailReg.test(this.account)) {
this.$toast('註冊賬號格式不正確');
} else {
this.timer()
}
},
timer() {
if (this.time > 0) {
this.time--;
this.codetext = this.time + 'S後重試'; //剩餘秒數;
this.disabled = true;
console.log(this.disabled)
setTimeout(this.timer, 1000);
} else {
this.time = 60;
this.codetext = '獲取驗證碼'; // 獲取驗證碼
this.disabled = false;
}
},
}
1:一些正則判斷格式
判斷手機號:let mobileReg = /^1(3|4|5|7|8|9)\d{9}$/;
data中定義 account
let mobileReg = /^1(3|4|5|7|8|9)\d{9}$/;
if (!this.account) {
this.$toast('請輸入手機號'); // 請輸入郵箱
} else if (!mobileReg.test(this.account)) {
this.$toast('註冊賬號格式不正確');
} else {
console.log('賬號正確')
}
判斷郵箱:兩種方式那個都可以的
1:let mobileReg = /^1(3|4|5|7|8|9)\d{9}KaTeX parse error: Expected 'EOF', got '\d' at position 31: …Reg = /^[A-Za-z\̲d̲]+([-_.][A-Za-z…/;
data中定義 account
let emailReg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
if (!this.account) {
this.$toast('請輸入郵箱'); // 請輸入郵箱
} else if (!emailReg.test(this.account)) {
this.$toast('註冊賬號格式不正確');
} else {
console.log('賬號正確')
}
判斷手機號加郵箱的方法
data中定義 account
let mobileReg = /^1(3|4|5|7|8|9)\d{9}$/;
let emailReg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
if (!this.account) {
this.$toast('請輸入手機號或郵箱'); // 請輸入手機號或郵箱
} else if (!mobileReg.test(this.account) && !emailReg.test(this.account)) {
this.$toast('註冊賬號格式不正確');
} else {
console.log('賬號正確')
}
密碼的長短:
1:let pwdReg = /^.{6,16}KaTeX parse error: Expected 'EOF', got '\d' at position 37: …odeReg = /(?!^(\̲d̲+|[a-zA-Z]+|[~!…%&*?]+)$)^[\w~!@#$%&*?]{6,16}$/ //組合密碼 字母加數字