Implement verification code for mobile phone sending

Source: Internet
Author: User

Html:

<li>
<label class= "K" for= "" >
Mobile number:</label>
<span class= "V" >
<input class= "Psp-text" style= "width:90px; ime-mode:disabled; "type=" text "id=" Txtmobilecode "
Name= "Txtmobilecode" maxlength= "one" size= "one" onpaste= "return false"/>
<input type= "button" value= "Get Verification Code" onclick= "Setcode (true);" id= "Btncode"/>
</span><em id= "Tiptel" ></em></li>

Jquery:

function Setcode (n) {
if ($ (' #txtMobileCode '). Length = 11) {
if (n)
$.ajax ({
Type: "Get",
DataType: "JSON",
URL: "Ajax.aspx?oper=telpcode&clienttime=" + (new Date (). GetTime ()),
Data: "Txtmobilecode=" + $ ("#txtMobileCode"). Val (),
Success:function (d) {
if (D.result = = "1") {
Alert ("Verification code sent successfully");
GetNumber ();
return true;
}
else {
Alert ("Failed to send verification code");
return false;
}
}
});
else {}
}
else {
}
}
var count = 5;
function GetNumber () {
$ ("#btnCode"). attr ("Disabled", "disabled");
$ ("#btnCode"). Val (count + "seconds after click to get")
count--;
if (Count > 0) {
SetTimeout (GetNumber, 1000);
}
else {
$ ("#btnCode"). Val ("Click to get Verification Code");
$ ("#btnCode"). attr ("Disabled", "" ");
Count = 5;
}
}

Ajax.aspx CS:

private void Ajaxtelpcode ()//Generate Verification code
{
Sms. Service SMS = new SMS. Service ();//SMS Service Interface
if (q ("Txtmobilecode")! = "")
{
String telp = q ("Txtmobilecode");//Page phone number
Random random = new random ();
String telcode = random. Next (100000, 999999). ToString ();//6-bit verification code
string s = sms.mt ("Xmysy", "FFF", Telp, "Your captcha is:" + telcode). ToString ();//Interface Send
if (s = = "0")
{
Xmldoc.load (HttpContext.Current.Server.MapPath ("~/telcode.xml"));//define the XML file to save the verification code and the phone good
XmlNode root = Xmldoc.selectsinglenode ("Tcode");
XmlNodeList nodelist = Xmldoc.selectsinglenode ("Tcode"). ChildNodes;
for (int i = 0; i < nodelist. Count; i++)//Read the original validation XML file
{
XmlElement XE = (XmlElement) nodelist. Item (i);
if (XE. GetAttribute ("tel") = = TELP)//Determine if the phone already exists and delete it to ensure that the code is unique and up-to-date, and "Resend"
{
Root. RemoveChild (XE);
if (I < nodelist. Count)
i = i-1;
}
}
Add a record to save the phone number and corresponding verification code
XmlElement xe1 = xmldoc.createelement ("Node");
Xe1. SetAttribute ("tel", telp);
XmlElement xesub1 = xmldoc.createelement ("Code");
Xesub1. InnerText = Telcode;
Xe1. AppendChild (XESUB1);

XmlElement xesub2 = xmldoc.createelement ("Tel");
Xesub2. InnerText = TELP;
Xe1. AppendChild (XESUB2);
Root. AppendChild (XE1);

Xmldoc.save (HttpContext.Current.Server.MapPath ("~/telcode.xml"));

This._response = Jsonresult (1, "Verification code sent successfully");//return content

}
Else
{
This._response = Jsonresult (0, "Error in verification code delivery");

}
}
Else
This._response = Jsonresult (0, "empty");
}

private void Ajaxregister ()//Register button
{
String _code = f ("Txtcode");
String _tel = f ("Txtmobilecode");
bool IsTrue = true;
DataSet ds = new DataSet ();
Ds. READXML (HttpContext.Current.Server.MapPath ("~/telcode.xml"));
DataTable dt = ds. Tables[0];
if (dt. Rows.Count > 0)
{
for (int i = 0; i < dt. Rows.Count; i++)
{
if (dt. rows[i]["Code"]. ToString () = = _code && dt. rows[i]["Tel"]. ToString () = = _tel)
{
IsTrue = false;
Break
}
Else
{
}

}

}
if (istrue)
{
Response.Write ("Jumbotcms.alert (' captcha error ', ' 0 ');");
Response.End ();
}

........

}

Xml:

<Tcode>
<node tel= "15980908000" >
<Code>696009</Code>
<Tel>15980908000</Tel>
</Node>
<node tel= "15980908001" >
<Code>689998</Code>
<Tel>15980908001</Tel>
</Node>
</Tcode>

Implement verification code for mobile phone sending

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.