vue中手機號,郵箱正則驗證以及60s發送驗證碼的執行個體,vue60s

來源:互聯網
上載者:User

vue中手機號,郵箱正則驗證以及60s發送驗證碼的執行個體,vue60s

今天寫了一個簡單的驗證,本來前面用的組件,但是感覺寫的組件在此項目不是很好用,由於用到的地方比較少,所以直接寫在了頁面中。

<div> <p class="fl">  <input name="phone" type="number" placeholder="手機號" v-model="phone"/>  <button type="button" :disabled="disabled" @click="sendcode" class="btns">{{btntxt}}</button> </p> <p class="fl" style="margin-left: 20px;">  <input type="text" placeholder="驗證碼"/> </p></div><input type="button" value="查詢" class="btns search" @click="query"/>

這裡是script裡的內容

export default {   data: function () {   return {    disabled:false,    time:0,    btntxt:"擷取驗證碼",    formMess:{     email:this.email,     phone:this.phone    }   }   },   mounted: function () {       },  methods:{   //驗證手機號碼部分   sendcode(){    var reg=11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/;    //var url="/nptOfficialWebsite/apply/sendSms?mobile="+this.ruleForm.phone;    if(this.phone==''){     alert("請輸入手機號碼");    }else if(!reg.test(this.phone)){     alert("手機格式不正確");    }else{     this.time=60;     this.disabled=true;     this.timer();     /*axios.post(url).then(      res=>{      this.phonedata=res.data;     })*/    }   },   timer() {    if (this.time > 0) {      this.time--;      this.btntxt=this.time+"s後重新擷取";      setTimeout(this.timer, 1000);    } else{      this.time=0;      this.btntxt="擷取驗證碼";      this.disabled=false;    }   },   query(){    var formMess=this.formMess    Axios.post(api+"/order/select/reception", formMess)     .then(function (res) {      if(res.data.code==200){       console.log(res.data.data);       this.productResult=res.data.data;       this.productResult.length=3;      }else if(res.data.code==400){       alert(res.data.message)      }           }.bind(this))   },   //郵箱驗證   sendEmail(){    var regEmail= /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;    if(this.email==''){     alert("請輸入郵箱");    }else if(!regEmail.test(this.email)){     alert("郵箱格式不正確");    }   }  } }

以上這篇vue中手機號,郵箱正則驗證以及60s發送驗證碼的執行個體就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.