Instance for vue mobile phone number, email RegEx verification, and 60 s verification code sending, vue60s

Source: Internet
Author: User

Instance for vue mobile phone number, email RegEx verification, and 60 s verification code sending, vue60s

Today, I wrote a simple verification code for the components I used earlier. However, I feel that the components I wrote are not very useful in this project. Because they are used less often, they are directly written on the page.

<Div> <p class = "fl"> <input name = "phone" type = "number" placeholder = "mobile phone number" 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 =" Verification Code "/> </p> </div> <input type =" button "value =" query "class =" btns search "@ click =" query "/>

The content in the script

Export default {data: function () {return {disabled: false, time: 0, btntxt: "Get verification code", formMess: {email: this. email, phone: this. phone }}, mounted: function () {}, methods: {// verify the mobile phone number part 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 ("Enter your mobile phone number");} else if (! Reg. test (this. phone) {alert ("Incorrect mobile phone format");} 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 and then get again"; setTimeout (this. timer, 1000);} else {this. time = 0; this. btntxt = "get verification code"; this. disabled = false ;}, query () {var formMess = this. formMess Axios. post (api + "/order/select /Prediction ", 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)}, // mail verification 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 (" Enter your email address ");} else if (! RegEmail. test (this. email) {alert ("Incorrect email format ");}}}}

In the above vue, the mobile phone number, email RegEx verification, and 60 s verification code sending examples are all the content shared by Alibaba Cloud. I hope you can provide a reference and support for the customer's home.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.