asp.net实现中英文多域名检测的方法

/****写入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 runat="server" /> // <table cellpadding="0" cellspacing="1"> <tr> <td> <asp:CheckBox Text=".com" runat="server" /> </td> <td> <asp:CheckBox Text=".cn" runat="server" /> </td> <td> <asp:CheckBox Text=".org" runat="server" /> </td> <td> <asp:CheckBox Text=".net" runat="server" /> </td> <td> <asp:CheckBox Text=".info" runat="server" /> </td> </tr> <tr> <td> <asp:CheckBox Text=".com.cn" runat="server" /> </td> <td> <asp:CheckBox Text=".cc" runat="server" /> </td> <td> <asp:CheckBox Text=".org.cn" runat="server" /> </td> <td> <asp:CheckBox Text=".net.cn" runat="server" /> </td> <td> <asp:CheckBox Text=".in" runat="server" /> </td> </tr> <tr> <td> <asp:CheckBox Text=".co.uk" runat="server" /> </td> <td> <asp:CheckBox Text=".tv" runat="server" /> </td> <td> <asp:CheckBox Text=".org.uk" runat="server" /> </td> <td> <asp:CheckBox Text=".us" runat="server" /> </td> <td> <asp:CheckBox Text=".me.uk" runat="server" /> </td> </tr> <tr> <td> <asp:CheckBox Text=".ltd.uk" runat="server" /> </td> <td> <asp:CheckBox Text=".biz" runat="server" /> </td> <td> <asp:CheckBox Text=".网络" runat="server" /> </td> <td> <asp:CheckBox Text=".公司" runat="server" /> </td> <td> <asp:CheckBox Text=".中国" runat="server" /> </td> </tr> </table>

第二步:在后台页面中写入方法

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjyjxx.html