本文实例讲述了asp.net实现中英文多域名检测的方法。,具体如下:
第一步:在前台页面中写入js代码和相关控件
/****写入js代码****/<%-- 域名检测 --%><script type="text/javascript"> //判断输入的是否为中文域名 function IsChDomain(domainStr) { var flag = false; var compStr = "ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_0123456789"; var domainLength = domainStr.length;//判断字符长度 for(var i = 0;i < domainLength;i++) { var temp = domainStr.charCodeAt(i); if(temp >= 10000)//含有字符编码大于10000的字符判断为中文,不太严格 { flag=true; } else { var temp2 = compStr.indexOf(domainStr.charAt(i)); if(temp2 == -1) { flag = false; break; } } } return flag; } //判断输入的是否为英文域名 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; break; } else { flag = true; } } return flag; } //中国等不能注册英文域名,把相应的CheckBox的disabled属性设置为true, function Trim(domainStr) { return domainStr.replace(/(^s*)|(s*$)/g, ""); } //验证域名是哪一类型的 function checkDomainType() { var domainName = document.getElementById("txtDomainName").value; domainName = Trim(domainName);//去掉输入的特殊符号 if(IsChDomain(domainName))//调用中文域名----------验证方法 { setCheckBox(true); } else if(IsEnDomain(domainName))//调用英文域名-----验证方法 { setCheckBox(false); } } //为CheckBox复选框的Checked属性赋值 function setCheckBox(flag) { document.getElementById("chkcom").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; } //检查输入的字符规范// function checkValue()// {// if(document.getElementById("txtDomainName").value=='')// {// alert('请输入域名!');// return false;// }// if(document.getElementById("txtDomainName").value.length >= 60)// {// alert('域名长度不能超过60个字符!');// return false;// }// for(var i = 0;i < document.getElementById("txtDomainName").value.length;i++)// {// if(document.getElementById("txtDomainName").value.charAt(i) == ' ')// {// alert('域名中不能含有空格!');// return false;// break;// }// }// }</script>/***写入相关控件***///用于显示查询的结果<asp:Panel ID="indexpnlDomainName" runat="server" Width="100%" />//<table width="373" border="0" cellpadding="0" cellspacing="1"> <tr> <td width="74" height="41"><asp:CheckBox ID="chkcom" Text=".com" runat="server" /> </td> <td width="71" height="41"> <asp:CheckBox ID="chkcn" Text=".cn" runat="server" /> </td> <td width="79" height="41"> <asp:CheckBox ID="chkorg" Text=".org" runat="server" /> </td> <td width="71" height="41"> <asp:CheckBox ID="chknet" Text=".net" runat="server" /> </td> <td width="72" height="41"> <asp:CheckBox ID="chkinfo" Text=".info" runat="server" /> </td> </tr> <tr> <td width="74" height="41"> <asp:CheckBox ID="chkcomcn" Text=".com.cn" runat="server" /> </td> <td height="41"> <asp:CheckBox ID="chkcc" Text=".cc" runat="server" /> </td> <td height="41"> <asp:CheckBox ID="chkorgcn" Text=".org.cn" runat="server" /> </td> <td height="41"> <asp:CheckBox ID="chknetcn" Text=".net.cn" runat="server" /> </td> <td height="41"> <asp:CheckBox ID="chkin" Text=".in" runat="server" /> </td> </tr> <tr> <td width="74" height="40"> <asp:CheckBox ID="chkcouk" Text=".co.uk" runat="server" /> </td> <td height="41"> <asp:CheckBox ID="chktv" Text=".tv" runat="server" /> </td> <td height="41"> <asp:CheckBox ID="chkorguk" Text=".org.uk" runat="server" /> </td> <td height="41"> <asp:CheckBox ID="chkus" Text=".us" runat="server" /> </td> <td height="41"> <asp:CheckBox ID="chkmeuk" Text=".me.uk" runat="server" /> </td> </tr> <tr> <td width="74" height="41"> <asp:CheckBox ID="chkltduk" Text=".ltd.uk" runat="server" /> </td> <td height="41"> <asp:CheckBox ID="chkbiz" Text=".biz" runat="server" /> </td> <td height="41"> <asp:CheckBox ID="chknetwork" Text=".网络" runat="server" /> </td> <td height="41"> <asp:CheckBox ID="chkcompany" Text=".公司" runat="server" /> </td> <td height="41"> <asp:CheckBox ID="chkchina" Text=".中国" runat="server" /> </td> </tr></table>
新闻热点
疑难解答
图片精选