JQuery Front-end implementation of mobile phone verification code

Source: Internet
Author: User

Html

<inputID= "Phone"type= "text"name= "Phone"><inputID= "Checkcode"type= "text"name= "Code"><ButtonID= "Code-btn">Click to send verification code</Button>

JS Code

varCode = "";//Receive Verification Code$ (' #code-btn '). Click (function(){  varCount = 5; varphone=$ ("#phone"). Val ();//Mobile phone number    varReg_phone =/1\d{10}/; if(!reg_phone.test (phone)) {//Verify that your phone conforms to the formatAlert ("Fill in the phone number"); return false; }     //Start Timing$ ("#code-btn"). attr (' disabled ', ' disabled '); $("#code-btn"). HTML ("Countdown" + Count + "seconds")); varTimer = SetInterval (function() {count--; $("#code-btn"). HTML ("Countdown" + Count + "seconds")); if(count==0) {clearinterval (timer); $("#code-btn"). attr ("Disabled",false);//Enable button$ ("#code-btn"). HTML ("Resend Verification Code")); Code= "";//clear the verification code. If you do not clear, after the time, the input received the verification code is still valid      }    },1000); //send processing data to the background$.ajax ({type:"POST",//transfer by postDataType: "Text",//data format: JSONURL: ",//Destination AddressData: "phone=" + Phone + "&code=" +code, Error:function(XMLHttpRequest, Textstatus, Errorthrown) {}, Success:function(msg) {}}); 

JQuery Front-end implementation of mobile phone verification code

Related Article

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.