This paper illustrates the method of asp.net in English and Chinese domain detection. Share to everyone for your reference, specific as follows:
First step: Write JS code and related controls in the foreground page
/**** Write JS code ****/<%--domain name detection--%> <script type= "Text/javascript" >//Judge whether the input is a Chinese domain name function ischdomain (domain
STR) {var flag = false;
var compstr = "abcdefghigklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz-_0123456789"; var domainlength = domainstr.length;//Judge character length for (var i = 0;i < domainlength;i++) {var temp = domainstr.ch
Arcodeat (i);
if (temp >= 10000)//contains character encoding greater than 10000 characters judged for Chinese, not too strict {flag=true;
else {var temp2 = Compstr.indexof (Domainstr.charat (i));
if (Temp2 = = 1) {flag = false;
Break
}} return flag;
//Judge whether the input is English domain name function isendomain (domainstr) {var flag = false;
var compstr = "abcdefghigklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz-_0123456789";
var domainlength = domainstr.length;
for (var i = 0;i<domainlength;i++) {if (Compstr.indexof (Domainstr.charat (i)) = = 1) {flag = false;
Breakelse {flag = true;
} return flag; //China can not register English domain name, the corresponding CheckBox disabled property set to True, function Trim (domainstr) {return domainstr.replace (^s*) | (
s*$)/g, "");
//verify which type of function the domain name is checkdomaintype () {var domainname = document.getElementById ("Txtdomainname"). Value; DomainName = Trim (domainname)//Remove the input special symbol if (Ischdomain (domainname))//Invoke the Chinese domain name----------authentication method {Setcheckbox (tr
UE);
else if (Isendomain (domainname))//Call English Domain name-----authentication method {Setcheckbox (false); The Checked property assignment function Setcheckbox (flag) {document.getElementById ("chkcom") for the CheckBox check box. Disabled = Flag
;
document.getElementById ("Chknet"). Disabled = Flag;
document.getElementById ("chkorg"). Disabled = Flag;
document.getElementById ("CHKORGCN"). Disabled = Flag;
document.getElementById ("CHKCN"). Disabled = Flag;
document.getElementById ("CHKCOMCN"). Disabled = Flag; document.getElementById ("CHKNETCN"). Disabled = Flag;
document.getElementById ("CHKGOVCN"). Disabled = Flag;
document.getElementById ("Chkcouk"). Disabled = Flag;
document.getElementById ("chkbiz"). Disabled = Flag;
document.getElementById ("CHKCC"). Disabled = Flag;
document.getElementById ("Chktv"). Disabled = Flag;
document.getElementById ("Chkinfo"). Disabled = Flag;
document.getElementById ("Chkchina"). Disabled =!flag;
document.getElementById ("Chkcompany"). Disabled =!flag;
document.getElementById ("Chknetwork"). Disabled =!flag;
document.getElementById ("Chkorguk"). Disabled = Flag;
document.getElementById ("Chkus"). Disabled = Flag;
document.getElementById ("Chkmeuk"). Disabled = Flag;
document.getElementById ("Chkltduk"). Disabled = Flag; //Check the character specification entered//function CheckValue ()//{//if (document.getElementById ("Txtdomainname"). value== ")//{/ Alert (' Please enter the domain name!
');
return false; }//if (document.getElementById ("Txtdomainname"). Value.length>=//{//alert (' Domain name length cannot exceed 60 characters!)
');
return false; //For (var i = 0;i < document.getElementById ("Txtdomainname"). value.length;i++)//{//if (document. getElementById ("Txtdomainname"). Value.charat (i) = = ')//{//alert (' Domain name cannot contain spaces!)
');
return false;
Break /////} </script>/*** Write related control ***///To display query results <asp:panel id= "indexpnldomainname" runat= "Server" Wi Dth= "100%"/>//<table width= "373" border= "0" cellpadding= "0" cellspacing= "1" > <tr> <td width= "H" eight= "<asp:checkbox" > id= "chkcom" text= ". com" runat= "server"/> </td> <td width= "" "height=" 41 "
> <asp:checkbox id= "CHKCN" text= ". CN" runat= "Server"/> </td> <td width= "km" height= "a" > <asp:checkbox id= "chkorg" text= ". org" runat= "server"/> </td> <td width= "the" "height=" > <a
Sp:checkbox id= "Chknet" text= ". Net" runat= "Server"/> </td> <td width= "height=" > <asp:checkbox id= "chkinfo" text= ". Info" runat= "server"/> &L t;/td> </tr> <tr> width= "<td" height= "<asp:checkbox" > Id= CHKCOMCN "text=". com.cn "R
unat= "Server"/> </td> <td height= "i" > <asp:checkbox id= "chkcc" text= ". CC" runat= "Server"/> </td> <td height= "A" > <asp:checkbox id= "CHKORGCN" text= "org.cn runat=" "Server"/>
T <TD height= "A" > <asp:checkbox id= "CHKNETCN" text= ". net.cn" runat= "server"/> </td> <td Heigh t= "> <asp:checkbox id=" Chkin "text=". In "runat=" Server "/> </td> </tr> <tr> &
LT;TD width= "height=" > <asp:checkbox id= "Chkcouk" text= "co.uk". runat= "Server"/> </td> <TD height= > <asp:checkbox id= "Chktv" text= ". TV" runat= "Server"/> </td> <td Height = "a" > <Asp:checkbox id= "Chkorguk" text= ". org.uk" runat= "server"/> </td> <td height= "a" > <asp:che Ckbox id= "Chkus" text= ". US" runat= "server"/> </td> <td height= "A" > <asp:checkbox id= "chkm"
Euk "text=". me.uk "runat=" server "/> </td> </tr> <tr> <td width=" "" height= "" <asp:checkbox id= "Chkltduk" text=. ltd.uk runat= "Server"/> </td> <td height= "a" > & Lt;asp:checkbox id= "chkbiz" text= ". Biz" runat= "server"/> </td> <td height= "a" > <asp:check Box id= "Chknetwork" text= ". Network" runat= "server"/> </td> <td height= "A" > <asp:checkbox id= "C" Hkcompany "text=". Company "runat=" server/> </td> <td height= "A" > <asp:checkbox id= "Chkchina"
text= ". China" runat= "server"/> </td> </tr> </table>
Step Two: Write methods in the background page
Using System;
Using System.Collections;
Using System.Configuration;
Using System.Data;
Using System.Linq;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Xml.Linq; Using System.Text; (class file namespace that needs to be introduced) using System.Net.Sockets; (class file namespace that needs to be introduced) using System.Text.RegularExpressions; (class file namespace that needs to be introduced) using System.Collections.Generic; (class file namespace that needs to be introduced) using System.Data.Common; (class file namespace that needs to be introduced) using System.Xml; (class file namespace that needs to be introduced) using System.IO; (class file namespace that needs to be introduced) using Microsoft.SqlServer.Server; (class file namespace that needs to be introduced) using System.Net;
(class file namespace to be introduced)//determine if the Chinese domain name (method) public static bool Ishaschzn (string domainname) {Regex regchzn = new Regex ("[A-龥]");
Match m = regchzn.match (domainname);
return m.success;
//Determine whether the domain name is registered (method) public static bool Isreg (string domainname) {BOOL flag = false;
string dm = HttpContext.Current.Server.UrlEncode (domainname); try {///Judge methods are very many, such as open remote file processing strings, and so on, the method used here is not very efficient WebClient WC = new WebClient (); String xmlstr = WC.
Downloadstring ("http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=" + DM);
StringReader sr = new StringReader (XMLSTR);
XmlTextReader xr = new XmlTextReader (SR); while (XR. Read ()) {if (XR). Isstartelement ("original")) {XR.
Read (); if (XR.
Value.substring (0, 3) = = "210") {flag = true;
Break
else {flag = false;
Break
}} return flag;
catch {return false; }//button event protected void Imgbtncheck_click (object sender, ImageClickEventArgs e) {string txtym = This.txtYMname.Text.
Trim (); if (Txtym = = "") {Scriptmanager.registerstartupscript (this, this.) GetType (), "SC", "alert (' Sorry, domain name cannot be empty!") '); ", true);
else {string domainname = This.txtYMname.Text.Trim (); ilist<string> domainlist = new list<string> ();//save domain name and suffix domainlist.add (domainname);//list<string
> first element save domain name, other element is domain name suffix Determine if the Chinese domain name if (ISHASCHZN (domainname)) {if (Chkchina). Checked) Domainlist.add (Chkchina).
Text); if (Chkcompany. Checked) Domainlist.add (Chkcompany).
Text); if (chknetwork. Checked) Domainlist.add (chknetwork).
Text); else {if (chkcom). Checked) Domainlist.add (chkcom).
Text); if (chknet. Checked) Domainlist.add (chknet).
Text); if (chkorg. Checked) Domainlist.add (chkorg).
Text); if (CHKORGCN. Checked) Domainlist.add (CHKORGCN).
Text); if (CHKCN. Checked) Domainlist.add (CHKCN).
Text); if (CHKCOMCN. Checked) Domainlist.add (CHKCOMCN).
Text); if (CHKNETCN. Checked) Domainlist.add (CHKNETCN).
Text); if (chkinfo. Checked) Domainlist.add (chkinfo).
Text); if (Chkcouk. Checked) Domainlist.add (Chkcouk).
Text); if (chkbiz. Checked) Domainlist.add (chkbiz).
Text); if (CHKCC. Checked) Domainlist.add (CHKCC).
Text); if (CHKTV. Checked) Domainlist.add (CHKTV).
Text); if (Chkorguk. Checked) Domainlist.add (Chkorguk).
Text); if (Chkus. Checked) Domainlist.add (Chkus).
Text); if (cHkmeuk. Checked) Domainlist.add (Chkmeuk).
Text); if (Chkltduk. Checked) Domainlist.add (Chkltduk).
Text); if (Chkin. Checked) Domainlist.add (Chkin).
Text);
} session["Localpnldomainname"] = DomainList; Displays the domain name result of the first page query if (session["localpnldomainname"]!= null) {ilist<string> il = (ilist<string>) sess
ion["Localpnldomainname"]; if (IL.
Count > 1) {string dm = il[0];
String dname;
Label LBL; for (int i = 1; i < IL. Count;
i++) {dname = DM + il[i];
if (Isreg (dname)) {lbl = new Label ();
Lbl.id = "LBL" + i.tostring (); LbL. Text = string.
Format ("<p style= ' Font-size:12px;color:green ' >{0} can be registered!</p>", DM + il[i]);
INDEXPNLDOMAINNAME.CONTROLS.ADD (LBL);
else {lbl = new Label ();
Lbl.id = "LBL" + i.tostring (); LbL. Text = string. Format ("<p><a target= ' _blank ' style= ' color:red;font-size:12px ' title= '") Click JumpTo the domain name ' href= ' http://www. {0} ' >{1} has been registered! </a> <a target= ' _blank ' style= ' font-size:12px;color:red ' title= ' Click to view Details ' href= ' HTTP://WHOIS.HICHINA.COM/CGI-BIN/WHOIS?DOMAIN={2} ' >[view]</a></p> ', DM + il[i], DM + il[i],
Server.URLEncode (DM + il[i]));
INDEXPNLDOMAINNAME.CONTROLS.ADD (LBL);
}
}
}
}
}
}
More interested readers of asp.net related content can view the site topics: "asp.net string operation tips Summary", "asp.net operation JSON tips summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", " asp.net Ajax Skills Summary topic and the "ASP.net cache operation skills Summary."
I hope this article will help you to ASP.net program design.