一些常用的验证
function checkAll() {
//debugger;
var strMessage = "";
if ($("#ddlAdmcorp").val() == "qxz") {
strMessage += "请选择[行政公司]!\n";
$("#ddlAdmcorp").focus();
}
if ($("#ddlAdmdep").val() == "qxz") {
strMessage += "请选择[部门]!\n";
$("#ddlAdmdep").focus();
}
debugger;
if ($.trim($("#txtProperty").val()).length ==0) {
strMessage += "[物业名称]不能为空!\n";
$("#txtProperty").focus();
}
if ($("#ddlProvince").val() == "qxz") {
strMessage += "请选择[省]!\n";
$("#ddlProvince").focus();
}
if ($("#ddlCity").val() == "qxz") {
strMessage += "请选择[市]!\n";
$("#ddlCity").focus();
}
if ($("#ddlCountry").val() == "qxz") {
strMessage += "请选择[县]!\n";
$("#ddlCountry").focus();
}
if ($("#ddlBusinessCircleType").val() == "qxz") {
strMessage += "请选择[商圈类型]!\n";
$("#ddlBusinessCircleType").focus();
}
if ($.trim($("#txtArea").val()).length == 0) {
strMessage += "[面积]不能为空!\n";
$("#txtArea").focus();
}
else {
//验证面积输入的是否为数字
var myreg = /^[0-9]+(.[0-9]{2})?$/;
if (!myreg.test($("#txtArea").val())) {
strMessage += "[面积]请输入正整数或者两位小数的正整数!\n";
}
}
if ($.trim($("#txtContractSignDate").val()).length == 0) {
strMessage += "[合同签订日期]不能为空!\n";
$("#txtContractSignDate").focus();
}
if ($.trim($("#txtContractStartDate").val()).length == 0) {
strMessage += "[合同起始日期]不能为空!\n";
$("#txtContractStartDate").focus();
}
if ($.trim($("#txtContractEndDate").val()).length == 0) {
strMessage += "[合同终止日期]不能为空!\n";
$("#txtContractEndDate").focus();
}
//验证输入的日期格式
var fmt = "yyyy-MM-dd";
var dateFlg;
dateFlg = isDate($.trim($("#txtContractSignDate").val()), fmt);
if (!dateFlg)
strMessage += "[合同签订日期]格式不正确!\n";
dateFlg = isDate($.trim($("#txtContractStartDate").val()), fmt);
if (!dateFlg)
strMessage += "[合同开始日期]格式不正确!\n";
dateFlg = isDate($.trim($("#txtContractEndDate").val()), fmt);
if (!dateFlg)
strMessage += "[合同终止日期]格式不正确!\n";
//起始日期不能小于签订日期
if ($("#txtContractStartDate").val()<$("#txtContractSignDate").val() ) {
strMessage += "合同[起始日期]不能小于[签订日期]!\n";
}
//合同 终止日期不能小于起始日期
if ($("#txtContractEndDate").val() < $("#txtContractStartDate").val()) {
strMessage += "合同[终止日期]不能小于[起始日期]!\n";
}
if ($.trim($("#txtLessor").val()).length == 0) {
strMessage += "[出租人]不能为空!\n";
$("#txtLessor").focus();
}
if ($.trim($("#ddlLessorType").val()).length == "qxz") {
strMessage += "[出租人类型]不能为空!\n";
$("#ddlLessorType").focus();
}
if ($.trim($("#txtContact").val()).length == "") {
strMessage += "[联系人]不能为空!\n";
$("#txtContact").focus();
}
if ($.trim($("#txtLessee").val()).length == "") {
strMessage += "[承租人]不能为空!\n";
$("#txtLessee").focus();
}
if ($("#ddlRentPayTerms").val() == "qxz") {
strMessage += "请选择[租金支付方式]!\n";
$("#ddlRentPayTerms").focus();
}
//验证物业邮编(如果不为空)
if ($.trim($("#txtPostcode").val()).length!=0) {
var myreg = /^[[0-9]{6}$/;
if (!myreg.test($.trim($("#txtPostcode").val()))) {
strMessage += "请输入正确的[邮编]!\n";
$("#txtPostcode").focus();
}
}
//todo
//验证日期格式
//验证签订日期
//验证起始日期是否大于终止日期
//验证联系人邮编
if ($.trim($("#txtContactPostcode").val()).length!=0) {
var myreg = /^[[0-9]{6}$/;
if (!myreg.test($.trim($("#txtPostcode").val()))) {
strMessage += "请输入正确的[联系人邮编]!\n";
$("#txtContactPostcode").focus();
}
}
//验证联系人email
if ($.trim($("#txtContactEmail").val()).length!= 0) {
var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
if (!myreg.test($.trim($("#txtContactEmail").val()))) {
strMessage+="请输入正确的Email!\n"
$("txtContactEmail").focus();
}
}
//免租期天数
if ($.trim($("#txtFreeRentDays").val()).length!=0) {
//验证是否为正整数
var myreg = /^([1-9])+$/;
if (!myreg.test($("#txtFreeRentDays").val())) {
strMessage += "[免租期天数]只能输入正整数!\n"
$("txtContactEmail").focus();
}
}
//月租金
if ($.trim($("#txtRentMonth").val()).length!=0) {
var myreg = /^[0-9]+(.[0-9]{2})?$/;
if (!myreg.test($.trim($("#txtRentMonth").val()))) {
strMessage += "[月租金]请输入正整数或者两位小数的正整数";
$("#txtRentMonth").focus();
}
}
if (strMessage.length != 0) {
alert(strMessage);
return false;
}
else {
return true;
}