日期:2014-05-16 浏览次数:20377 次
js通用数据检测方法,现在只完成js端大体功能,随会追加php端代码,用户只在php点指定检测类型,会自动生成客户端js检测代码,从而做到只定义一次检测代码实现客户端服务端全部检测,让程序制作更方便。下面退出js端的代码。
submitCheckFunc.js
//******************************************************
//通用JS客户端数据检测 v1.0.20110705
//作者:ljl_xyf? http://www.my400800.cn
//******************************************************/
function submitCheckFunc() {
??? this.CheckObjArr = Array();
}
submitCheckFunc.prototype={
??? ErrMsg:"",
??? ErrObj:Array(),
??? CheckObjArr:Array(),//要检测的对象存放
??? SetFocusObj:null,
??? //____________________对象空判断__________________
??? IsNotNull:function(checkId){
??????? var checkobj = this.GetElementX(checkId);
??????? strType = checkobj.type;
??????? if(strType.indexOf("select")<0 ){
??????????? var checkvalue = checkobj.value;
??????????? if(_IsNull(checkvalue)){
??????????????? return false;
??????????? }
??????? }else{
??????????? var blCheckOk = false;
??????????? for(var i=checkobj.length-1;i>=0;i--){
??????????????? var rOption =checkobj[i];
??????????????? if(rOption.selected == true){
??????????????????? if(rOption.value!=""){
??????????????????????? blCheckOk =? true;
??????????????????? }
??????????????? }
??????????? }
??????????? return blCheckOk;
??????? }
??????? return true;
??????????????
??? },
???
??? //____________________是否是数字检测______________
??? IsFloat:function(oNum){
??????? if(!oNum) return false;
??????? var strP=/^\d+(\.\d+)?$/;
??????? if(!strP.test(oNum)){
??????????? return false;
??????? }
??????? try{
??????????? if(parseFloat(oNum)!=oNum){
??????????????? return false;
??????????? }
??????? } catch(ex)?? {
??????????? return false;
??????? }
??????? return true;??
??? },
??? //____________________验证整数____________________
??? IsInteger:function(checkNum){
??????? var regu = /^[-]{0,1}[0-9]{1,}$/;
??????? return regu.test(checkNum);
??? },
??? //____________________验证邮箱地址________________
??? IsEmail:function(strEmail){
??????? if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
??????????? return true;
??????? return false;
??? },
??? //____________________是否小于最大值______________
??? IsLessMax:function(strValue,strMaxValue){
??????
??????? if(this.IsFloat(strValue)){??????????
??????????? if((strValue/1)>(strMaxValue/1)){
??????????????? return false;
??????????? }
??????? }
??????? return true;
???????????????
??? },
??? //____________________是否大于最小值______________
??? IsGreaterMin:function(strValue,strMaxValue){
??????? if(this.IsFloat(strValue)){
??????????? if((strValue/1)<(strMaxValue/1)){
??????????????? return false;
??????????? }
??????? }
??????? return true;
??? },
???
??? //____________________是否小于最大长度____________
??? IsLessMaxLen:function(strValue,iMaxlen){
??????? if(!this._isNull(strValue)){
??????????? if(strValue.length>iMaxlen){
??????????????? return false;
??????????? }???????????
??????? }
??????? return true;
??? },
???
??? //____________________是否大于最小长度____________
??? IsGreaterMinLen:function(strValue,iMinlen){
??????? if(!this._isNull(strValue)){
??????????? if(strValue.length<iMinlen){
??????????????? return false;
??????????? }
??????? }
??????? return true;
??? },
???
??? //____________________是否是日期检测______________
??? IsDate:function(strValue){
??????? //如果为空,则通过校验
??????? if(this._isNull(strValue))
??????????? return true;
??????? var pattern = /^((d{4})|(d{2}))-(d{1,2})-(d{1,2})$/g;
??????? if(!pattern.test(strValue))