界面控件输入判断JS
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript" type="text/javascript">
//--------------------------------------------------------------------
//验证类
//功能:在客户端表单项验证
//返回结果: True Or False
//参数说明:
//1--验证对象(格式Fomr.TextBox)
//2--验证对象名称
//3--验证类型(自定义/非空/数字/货币/整型/浮点/身份证/电子邮件/三字代码/日期)
//4--自定义正则表达式(当验证类型为“自定义”时使用此项)
//5--验证结果错误信息(空:返回自定义错误信息 非空:返回自身)
//--------------------------------------------------------------------
function CheckFormData(CheckObj,Name,CheckType,CustomReg,ErrMeg)
{
//属性
this.CheckObj = CheckObj;
this.Name = Name;
this.CheckType = CheckType;
this.CustomReg = CustomReg;
this.Result = true;
this.ErrMeg = ErrMeg;
this.Reg = null;
this.Format = "";
//方法
this.doReg = function(reg,op)
{
return reg.test(op);
}
this.ChkReg = function()
{
if( !this.doReg(this.Reg,CheckObj.value) )
{
this.DoReturn(false,"无效的");
}
}
this.ChkEmpty = function()
{
if( CheckObj.value == "" )
{
this.DoReturn(false,"请输入");
}
}
this.DoReturn = function(re,strErr)
{
this.Result = re;
if( this.ErrMeg == "" )
{
this.ErrMeg = strErr + " " + this.Name + " !" + this.Format;
}
}
this.TextCheck = function()
{
switch( this.CheckType )
{
case "自定义":
this.Reg = this.CustomReg;
this.ChkReg();
break;
case "非空":
this.ChkEmpty();
break;
case "数字":
this.Reg = /^\d+$/;
this.Format = " [ 请输入数字 ]";
this.ChkReg();
break;
case "货币":
this.Reg = /^\d+(\.\d+)?$/;
this.ChkReg();
break;
case "整型":
this.Reg = /^[-\+]?\d+$/;
this.Format = " [ 请输入数字 ]";
this.ChkReg();
break;
case "浮点":
this.Reg = /^(-?\d+)(\.\d+)?$/;
this.Format = " [ 正确格式:12.5 ]";
this.ChkReg();
break;
case "身份证":
this.Reg = /^\d{15}(\d{2}[A-Za-z0-9])?$/;
this.ChkReg();
break;
case "电子邮件":
this.Reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
this.Format = " [ 请输入正确的Email格式 ]";
this.ChkReg();
break;
case "三字码":
this.Reg = /^[A-Za-z]{3}/;
this.Format = " [请输入正确的三字代码]";
this.ChkReg();
break;
case "日期":
this.Reg = /^([0-9]{4}|[0-9]{2})[-]([0]?[1-9]|[1][0-2])[-]([0]?[1-9]|[1|2][0-9]|[3][0|1])$/;
this.Format = " [ 正确格式:年-月-日 ]";
this.ChkReg();
break;
}
}
}
function checkForm()
{
var box;
var strSelectList = "";
var strMsg = "";
if (fmDetail.clickButtonID.value == "btnToSelect")
{
for (var i=0; i<fmDetail.elements.length; i++)
{
box = fmDetail.elements[i];
if (box.name == "TicketID" && box.checked)
{
strSelectList += "," + box.value;
}
}
if (strSelectList == "")
{
alert("请选择要操作的记录");
return false;
}
else
{
if (fmDetail.selectedList.value != "")
{
fmDetail.selectedList.value += "," + strSelectList.substring(1, strSelectList.length);
}
else
{
fmDetail.selectedList.value += strSelectList.substring(1, strSelectList.length);
}
}
}
else if (fmDetail.clickButtonID.value == "btnToCancelSelect"
|| fmDetail.clickButtonID.value == "btnOK"
|| fmDetail.clickButtonID.value == "btnVerify"
|| fmDetail.clickButtonID.value == "btnThaw"
|| fmDetail.clickButtonID.value == "btnDeductFee")
{
if (fmDetail.clickButtonID.value == "btnOK"
|| fmDetail.clickButtonID.value == "btnVerify"
|| fmDetail.clickButtonID.value == "btnThaw"
|| fmDetail.clickButtonID.value == "btnDeductFee")
{
for (var i=0; i<fmDetail.elements.length; i++)
{
box = fmDetail.elements[i];
if (box.name == "cancelTicketID")
{
strSelectList += "," + box.value;
}
}
}
else
{
for (var i=0; i<fmDetail.elements.length; i++)
{
box = fmDetail.elements[i];
if (box.name == "cancelTicketID" && box.checked)
{
strSelectList += "," + box.value;
}
}
}
if (strSelectList == "")
{
if (fmDetail.clickButtonID.value == "btnOK"
|| fmDetail.clickButtonID.value == "btnVerify"
|| fmDetail.clickButtonID.value == "btnThaw"
|| fmDetail.clickButtonID.value == "btnDeductFee")
{
alert("请先选择要处理的机票记录");
}
else
{
alert("请选择要取消的记录");
}
return false;
}
else
{
fmDetail.cancelList.value = strSelectList.substring(1, strSelectList.length);
}
}
if (fmDetail.clickButtonID.value == "btnOK")
{
if (!checkDataValue())
{
return false;
}
//fmDetail.isSubmit.value = "Y";
}
if (fmDetail.clickButtonID.value == "btnVerify"
|| fmDetail.clickButtonID.value == "btnThaw"
|| fmDetail.clickButtonID.value == "btnDeductFee")
{
if (fmDetail.isUpdateAccreditMoney.value == "N")
{
alert("请确认索权金额,点击“确定”更新索权金额后才能打印相应的申请表。");
return false;
}
if (fmDetail.clickButtonID.value == "btnVerify")
{
strMsg = "该操作将会使所有选中机票的支付状态改为“正在验证”,您确定吗?";
}
else if (fmDetail.clickButtonID.value == "btnThaw")
{
strMsg = "该操作将会使所有选中机票的支付状态改为“正在解冻”,您确定吗?";
}
else if (fmDetail.clickButtonID.value == "btnDeductFee")
{
strMsg = "该操作将会使所有选中机票的支付状态改为“正在扣款”,您确定吗?";
}
if (strMsg != "")
{
if (!confirm(strMsg))
{
return false;
}
}
}
return true;
}
//有效性验证
function checkDataValue()
{
var chkData;
//实扣金额
chkData = new CheckFormData(fmDetail.txtActualMoney,"","","","");
chkData.Name = "实扣金额";
chkData.CheckType = "非空";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
chkData.CheckType = "浮点";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
//授权金额
chkData = new CheckFormData(fmDetail.txtAccreditMoney,"","","","");
chkData.Name = "授权金额";
chkData.CheckType = "非空";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
chkData.CheckType = "浮点";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
//验证码
if (fmDetail.isJudgeVerifyCode.value == "Y" && "0,2,3".indexOf(fmDetail.ddlCreditCardStat.value) < 0)
{
chkData = new CheckFormData(fmDetail.txtVerifyCode,"","","","");
chkData.Name = "验证码";
chkData.CheckType = "非空";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
chkData.CheckType = "数字";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
if (fmDetail.txtVerifyCode.value.length < 7)
{
alert("验证码为七位,前四位为信用卡的最后四位,后三位为真正的校验码,请检查");
fmDetail.txtVerifyCode.focus();
return false;
}
else
{
var strCreditCardNO = document.getElementById("lbCreditCardNO").innerHTML;
if (fmDetail.txtVerifyCode.value.substring(0, 4) != strCreditCardNO.substring((strCreditCardNO.length-4), strCreditCardNO.length))
{
alert("验证码为七位,前四位为信用卡的最后四位,后三位为真正的校验码,请检查");
fmDetail.txtVerifyCode.focus();
return false;
}
}
}
//授权号
if ("0,2,3".indexOf(fmDetail.ddlCreditCardStat.value) < 0)
{
chkData = new CheckFormData(fmDetail.txtAccreditNO,"","","","");
chkData.Name = "授权号";
chkData.CheckType = "非空";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
}
//交易日期
chkData = new CheckFormData(fmDetail.txtPayTime,"","","","");
chkData.Name = "交易日期";
if ("0,2,3".indexOf(fmDetail.ddlCreditCardStat.value) < 0)
{
chkData.CheckType = "非空";
chkData.ErrMeg = "请选择/输入交易日期";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
}
if (fmDetail.txtPayTime.value != "")
{
chkData.CheckType = "日期";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
}
//备注最大value为500个字符:nvarchar(500)
if (fmDetail.txtRemark.value.replace(/(^\s*)|(\s*$)/g,"") != "")
{
if (fmDetail.txtRemark.value.replace(/(^\s*)|(\s*$)/g,"").length > 500)
{
alert("备注不能超过500个字符!");
fmDetail.txtRemark.focus();
return false;
}
fmDetail.txtRemark.value = fmDetail.txtRemark.value.replace(/(^\s*)|(\s*$)/g,"");
}
return true;
}
</script>
</HEAD>
<BODY>
<form id="fmDetail" onsubmit="return checkForm();" method="post" runat="server">
</form>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript" type="text/javascript">
//--------------------------------------------------------------------
//验证类
//功能:在客户端表单项验证
//返回结果: True Or False
//参数说明:
//1--验证对象(格式Fomr.TextBox)
//2--验证对象名称
//3--验证类型(自定义/非空/数字/货币/整型/浮点/身份证/电子邮件/三字代码/日期)
//4--自定义正则表达式(当验证类型为“自定义”时使用此项)
//5--验证结果错误信息(空:返回自定义错误信息 非空:返回自身)
//--------------------------------------------------------------------
function CheckFormData(CheckObj,Name,CheckType,CustomReg,ErrMeg)
{
//属性
this.CheckObj = CheckObj;
this.Name = Name;
this.CheckType = CheckType;
this.CustomReg = CustomReg;
this.Result = true;
this.ErrMeg = ErrMeg;
this.Reg = null;
this.Format = "";
//方法
this.doReg = function(reg,op)
{
return reg.test(op);
}
this.ChkReg = function()
{
if( !this.doReg(this.Reg,CheckObj.value) )
{
this.DoReturn(false,"无效的");
}
}
this.ChkEmpty = function()
{
if( CheckObj.value == "" )
{
this.DoReturn(false,"请输入");
}
}
this.DoReturn = function(re,strErr)
{
this.Result = re;
if( this.ErrMeg == "" )
{
this.ErrMeg = strErr + " " + this.Name + " !" + this.Format;
}
}
this.TextCheck = function()
{
switch( this.CheckType )
{
case "自定义":
this.Reg = this.CustomReg;
this.ChkReg();
break;
case "非空":
this.ChkEmpty();
break;
case "数字":
this.Reg = /^\d+$/;
this.Format = " [ 请输入数字 ]";
this.ChkReg();
break;
case "货币":
this.Reg = /^\d+(\.\d+)?$/;
this.ChkReg();
break;
case "整型":
this.Reg = /^[-\+]?\d+$/;
this.Format = " [ 请输入数字 ]";
this.ChkReg();
break;
case "浮点":
this.Reg = /^(-?\d+)(\.\d+)?$/;
this.Format = " [ 正确格式:12.5 ]";
this.ChkReg();
break;
case "身份证":
this.Reg = /^\d{15}(\d{2}[A-Za-z0-9])?$/;
this.ChkReg();
break;
case "电子邮件":
this.Reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
this.Format = " [ 请输入正确的Email格式 ]";
this.ChkReg();
break;
case "三字码":
this.Reg = /^[A-Za-z]{3}/;
this.Format = " [请输入正确的三字代码]";
this.ChkReg();
break;
case "日期":
this.Reg = /^([0-9]{4}|[0-9]{2})[-]([0]?[1-9]|[1][0-2])[-]([0]?[1-9]|[1|2][0-9]|[3][0|1])$/;
this.Format = " [ 正确格式:年-月-日 ]";
this.ChkReg();
break;
}
}
}
function checkForm()
{
var box;
var strSelectList = "";
var strMsg = "";
if (fmDetail.clickButtonID.value == "btnToSelect")
{
for (var i=0; i<fmDetail.elements.length; i++)
{
box = fmDetail.elements[i];
if (box.name == "TicketID" && box.checked)
{
strSelectList += "," + box.value;
}
}
if (strSelectList == "")
{
alert("请选择要操作的记录");
return false;
}
else
{
if (fmDetail.selectedList.value != "")
{
fmDetail.selectedList.value += "," + strSelectList.substring(1, strSelectList.length);
}
else
{
fmDetail.selectedList.value += strSelectList.substring(1, strSelectList.length);
}
}
}
else if (fmDetail.clickButtonID.value == "btnToCancelSelect"
|| fmDetail.clickButtonID.value == "btnOK"
|| fmDetail.clickButtonID.value == "btnVerify"
|| fmDetail.clickButtonID.value == "btnThaw"
|| fmDetail.clickButtonID.value == "btnDeductFee")
{
if (fmDetail.clickButtonID.value == "btnOK"
|| fmDetail.clickButtonID.value == "btnVerify"
|| fmDetail.clickButtonID.value == "btnThaw"
|| fmDetail.clickButtonID.value == "btnDeductFee")
{
for (var i=0; i<fmDetail.elements.length; i++)
{
box = fmDetail.elements[i];
if (box.name == "cancelTicketID")
{
strSelectList += "," + box.value;
}
}
}
else
{
for (var i=0; i<fmDetail.elements.length; i++)
{
box = fmDetail.elements[i];
if (box.name == "cancelTicketID" && box.checked)
{
strSelectList += "," + box.value;
}
}
}
if (strSelectList == "")
{
if (fmDetail.clickButtonID.value == "btnOK"
|| fmDetail.clickButtonID.value == "btnVerify"
|| fmDetail.clickButtonID.value == "btnThaw"
|| fmDetail.clickButtonID.value == "btnDeductFee")
{
alert("请先选择要处理的机票记录");
}
else
{
alert("请选择要取消的记录");
}
return false;
}
else
{
fmDetail.cancelList.value = strSelectList.substring(1, strSelectList.length);
}
}
if (fmDetail.clickButtonID.value == "btnOK")
{
if (!checkDataValue())
{
return false;
}
//fmDetail.isSubmit.value = "Y";
}
if (fmDetail.clickButtonID.value == "btnVerify"
|| fmDetail.clickButtonID.value == "btnThaw"
|| fmDetail.clickButtonID.value == "btnDeductFee")
{
if (fmDetail.isUpdateAccreditMoney.value == "N")
{
alert("请确认索权金额,点击“确定”更新索权金额后才能打印相应的申请表。");
return false;
}
if (fmDetail.clickButtonID.value == "btnVerify")
{
strMsg = "该操作将会使所有选中机票的支付状态改为“正在验证”,您确定吗?";
}
else if (fmDetail.clickButtonID.value == "btnThaw")
{
strMsg = "该操作将会使所有选中机票的支付状态改为“正在解冻”,您确定吗?";
}
else if (fmDetail.clickButtonID.value == "btnDeductFee")
{
strMsg = "该操作将会使所有选中机票的支付状态改为“正在扣款”,您确定吗?";
}
if (strMsg != "")
{
if (!confirm(strMsg))
{
return false;
}
}
}
return true;
}
//有效性验证
function checkDataValue()
{
var chkData;
//实扣金额
chkData = new CheckFormData(fmDetail.txtActualMoney,"","","","");
chkData.Name = "实扣金额";
chkData.CheckType = "非空";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
chkData.CheckType = "浮点";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
//授权金额
chkData = new CheckFormData(fmDetail.txtAccreditMoney,"","","","");
chkData.Name = "授权金额";
chkData.CheckType = "非空";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
chkData.CheckType = "浮点";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
//验证码
if (fmDetail.isJudgeVerifyCode.value == "Y" && "0,2,3".indexOf(fmDetail.ddlCreditCardStat.value) < 0)
{
chkData = new CheckFormData(fmDetail.txtVerifyCode,"","","","");
chkData.Name = "验证码";
chkData.CheckType = "非空";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
chkData.CheckType = "数字";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
if (fmDetail.txtVerifyCode.value.length < 7)
{
alert("验证码为七位,前四位为信用卡的最后四位,后三位为真正的校验码,请检查");
fmDetail.txtVerifyCode.focus();
return false;
}
else
{
var strCreditCardNO = document.getElementById("lbCreditCardNO").innerHTML;
if (fmDetail.txtVerifyCode.value.substring(0, 4) != strCreditCardNO.substring((strCreditCardNO.length-4), strCreditCardNO.length))
{
alert("验证码为七位,前四位为信用卡的最后四位,后三位为真正的校验码,请检查");
fmDetail.txtVerifyCode.focus();
return false;
}
}
}
//授权号
if ("0,2,3".indexOf(fmDetail.ddlCreditCardStat.value) < 0)
{
chkData = new CheckFormData(fmDetail.txtAccreditNO,"","","","");
chkData.Name = "授权号";
chkData.CheckType = "非空";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
}
//交易日期
chkData = new CheckFormData(fmDetail.txtPayTime,"","","","");
chkData.Name = "交易日期";
if ("0,2,3".indexOf(fmDetail.ddlCreditCardStat.value) < 0)
{
chkData.CheckType = "非空";
chkData.ErrMeg = "请选择/输入交易日期";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
}
if (fmDetail.txtPayTime.value != "")
{
chkData.CheckType = "日期";
chkData.TextCheck();
if(chkData.Result == false)
{
alert(chkData.ErrMeg);
chkData.CheckObj.focus();
return false;
}
}
//备注最大value为500个字符:nvarchar(500)
if (fmDetail.txtRemark.value.replace(/(^\s*)|(\s*$)/g,"") != "")
{
if (fmDetail.txtRemark.value.replace(/(^\s*)|(\s*$)/g,"").length > 500)
{
alert("备注不能超过500个字符!");
fmDetail.txtRemark.focus();
return false;
}
fmDetail.txtRemark.value = fmDetail.txtRemark.value.replace(/(^\s*)|(\s*$)/g,"");
}
return true;
}
</script>
</HEAD>
<BODY>
<form id="fmDetail" onsubmit="return checkForm();" method="post" runat="server">
</form>
</BODY>
</HTML>