asp.net 服务器控件 JS验证
`
//使用
OnClientClick="return checkselect()"
function checkselect() {
//验证下拉必选
var value = document.getElementById("ddlWorkType").value;
if (value == "0") {
document.getElementById("Label1").innerText = "请选择 选择工种!";
return false;
}
//验证非空
value = document.getElementById("txtorgcode").value;
if (value == "") {
alert("组织机构代码 不能为空!");
return false;
}
//正则验证
var Regex = /^(?:\w+\.?)*\w+@(?:\w+\.)*\w+$/;
value = document.getElementById("txtemail").value;
if (!Regex.test(value)) {
alert("电子邮件格式不正确,请重新输入。如:tkb@126.com");
document.getElementById("txtemail").value = "";
return false;
}
//列表选择
var GridView1 = document.getElementById("<%=GVListShow.ClientID %>");
var seleccheck = false;
for (i = 1; i < GridView1.rows.length; i++) {
if (GridView1.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked) {
seleccheck = true;
break;
}
}
if (!seleccheck) {
document.getElementById("Label1").innerText = "请选择 报名人员!";
return false;
}
//下拉列表
var CheckBox = document.getElementById("<%=ddlCompanyType.ClientID%>").getElementsByTagName("INPUT");
if (CheckBox != undefined) {
var j = 0;
for (var i = 0; i < CheckBox.length; i++) {
if (CheckBox[i].checked) {
j += 1;
}
}
if (j == 0) {
alert("请选择,企业类型!");
return false;
}
}
}`