jsチェックチェック

11219 ワード

/**
 *        
 */
function checkForm(checkGroup){
	if(typeof(checkGroup) == "undefined"){
		checkGroup = "";
	}
	var _val = 0;
	for(var i = 0 ; i < _checkFormList.length ; i++){
		var checkItem = _checkFormList[i];
		if(checkGroup == checkItem.group){
			var flag = true;
			var value = "";
			
			if(!(getobj(checkItem.id))){
				continue;
			}
			if(checkItem.controlType == "checkBox" || checkItem.controlType == "radio"){
				var _obj = document.getElementsByName(checkItem.id);
				var objarray=_obj.length;
				var chestr="";
				for (var k=0;k<objarray;k++){
					if(_obj[k].checked == true)
					{
						value += _obj[k].value;
					}
				}
			}else{
				value = getobj(checkItem.id).value;
			}
			
			
			if(checkItem.isNULL == true){
				flag = checkIsNULL(value);
			}
			if(flag&&value!=""){
				flag = checkItem.fun(value);
			}
			if(flag == false){
				if(checkItem.controlType == "checkBox" || checkItem.controlType == "radio"){
					var _obj = document.getElementsByName(checkItem.id);
					var objarray=_obj.length;
					var chestr="";
					for (var k=0;k<objarray;k++){
						_obj[k].nextSibling.style.backgroundColor="red";
					}
				}else{
					//getobj(checkItem.id).style.border = "red 1px solid";
					getobj(checkItem.id).style.background = "red";
				}
			
				_val++;
			}else{
				if(checkItem.controlType == "checkBox" || checkItem.controlType == "radio"){
					var _obj = document.getElementsByName(checkItem.id);
					var objarray=_obj.length;
					var chestr="";
					for (var k=0;k<objarray;k++){
						_obj[k].nextSibling.style.backgroundColor="";
					}
				}else{
					getobj(checkItem.id).style.backgroundColor = "";
				}
			}
		}
	}
	return _val>0?false:true;
}

function Mout(o){
	if(!o){
		return;
	}
	timer=setTimeout(function(){o.style.display="none";},100);
	swtemp=0;
}

function hiddiv(e,inputid){
    e=e||window.event;
    ev=e.target||e.srcElement;
    v=ev.innerText||ev.textContent;
    getobj(inputid).value=v;
    getobj(inputid+"mydiv").style.display="none";
}
	
function getobj(o){//    
    return document.getElementById(o);
}

function createDiv(_parent,_element,_id,_css){//   
    var newObj = document.createElement(_element);
    if(_id && _id!=""){
    	newObj.id=_id;
    }
    if(_css && _css!=""){
        newObj.setAttribute("style",_css);
        newObj.style.cssText = _css;
    }
    if(_parent && _parent!=""){
        var theObj=getobj(_parent);
        var parent = theObj.parentNode;
        if(parent.lastChild == theObj){
           theObj.appendChild(newObj);
        } 
        else{
           theObj.insertBefore(newObj, theObj.nextSibling);
        }
    }
    else{
    	document.body.appendChild(newObj);
    }
}


function offsetTop( elements ){ 
	var top = elements.offsetTop; 
	var parent = elements.offsetParent; 
	while( parent != null ){ 
		top += parent.offsetTop; 
		parent = parent.offsetParent; 
	}; 
	
	return top-$(document).scrollTop(); 
}; 
function offsetLeft( elements ){ 
	var left = elements.offsetLeft; 
	var parent = elements.offsetParent; 
	while( parent != null ){ 
		left += parent.offsetLeft; 
		parent = parent.offsetParent; 
	}; 
	return left; 
}; 

/**      **/

//      
function checkCarNo(value){
	if((/^[VKHBSLJNGCZE\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9\u8b66\u5b66\u6302]{1}$/g).test(value)){
		return true;
	}else{
		return false;
	}
}

//      
function checkIsNULL(value){
	if(value == "" || value == null || typeof(value) == "undefined"){
		return false;
	}else{
		return true;
	}
}

//  IP
function checkIP(value){
	var ip = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
	return ip.test(value) && (RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 < 256 && RegExp.$4 < 256); 
}

//    
function checkEmail(value){
	var myreg = /^([a-zA-Z0-9_-]+[_|\_|\.]?)*[a-zA-Z0-9_-]+@([a-zA-Z0-9_-]+[_|\_|\.]?)*[a-zA-Z0-9_-]+\.[a-zA-Z]{2,3}$/;
	return myreg.test(value);
}

//      
function checkTel(value){
	var partten = /^0(([1,2]\d)|([3-9]\d{2}))\d{7,8}$/;
	return partten.test(value);
}

//      
function checkPhone(value){
	var length = value.length;    
	return length == 11 && /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/.test(value);    
}
//     
function checkCard(value){  
    var len = value.length, re;  
    if (len == 15)  
        re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);  
    else if (len == 18)  
        re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\d)$/);  
    else{   
        return false;  
    }  
    var a = value.match(re);  
    if (a != null){  
        if (len==15){  
            var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]);  
            var B = D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];  
        }else{  
            var D = new Date(a[3]+"/"+a[4]+"/"+a[5]);  
            var B = D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];  
        }  
        if (!B){ 
            return false;  
        }  
    }  
  
    return true;  
}

/**
 *                  
 * 
 * @returns
 */
//        	
function checkDouble(value){
	var decimal = /^[1-9]\d*|^[1-9]\d*.\d*|0.\d*[1-9]\d*|0?.0+|0$/;
	return (decimal.test(value));
}

//             
function checkDecimal(value){
	var decimal = /^-?\d+(\.\d{1,2})?$/;
	return (decimal.test(value));
}

//      
function checkNum(s)
{
	var reg = new RegExp("^-?[0-9]*$");
	if(reg.test(s))
	{
	   return true;
	}
	return false;
}
//      
function checkInt(s)
{
	var reg = new RegExp("^[0-9]*$");
	if(reg.test(s))
	{
	   return true;
	}
	return false;
}

//         
function checkUnsignedInteger(s) 
{ 
	var reg = new RegExp("^[0-9]*$");
	if(reg.test(s))
	{
		if(s>0){
			return true;
		}else{
			return false;
		}
	   
	}
	return false;
}

//     
function checkDate(str) 
{ 
   var a = str.match(/^(\d{1,4})(-)(\d{1,2})\2(\d{1,2})$/);  
   if(a==null)return false;  
   if (a[3]>12 ||a[4]>31) //          
   { 
       return false;
   } 
   return true;
}
//     
function checkDateTime(str) 
{ 
  // var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;  
   var reg = /^(\d{1,4})(-)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;  
   var a = str.match(reg);  
   if(a==null)return false;
   if (a[3]>12 ||a[4]>31 || a[5]>23 || a[6]>59 || a[6]>59) //          
   { 
       return false;
   } 
   return true;
} 

//    (10:57:10) 
function checkTime(str) 
{ 
   var a = str.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/); 
   if (a == null) {return false;} 
   if (a[1]>23 || a[3]>59 || a[4]>59) 
   { 
       return false;
   } 
   return true; 
}
//         
function compareDate(d1,d2) 
{ 
    return ((new Date(d1.replace(/-/g,"\/"))) < (new Date(d2.replace(/-/g,"\/")))); 
}

//      
function checkString(value){
	 return /^[\Α-\¥\w]+$/.test(value);
}

function checkTelLength(value){
	if(value.length<7){
		return false;
	}
	 return true; 
	
}

function changeStrNull(str){
	if(typeof(str) == "undefined" || str == ""){
		str = "";
	}
	return str;
}

//       
function clearNoNum(obj,maxValue){
	if(obj.value.length>1){
		if(0 == obj.value.substr(0,1) && "." != obj.value.charAt(1)){
			obj.value = obj.value.replace(obj.value,"");
		}
	}
	//          ,    	
	obj.value = obj.value.replace(/[^\d.]/g,"");		
	//             .		
	obj.value = obj.value.replace(/^\./g,"");		
	//        .     .		
	obj.value = obj.value.replace(/\.{2,}/g,".");		
	//  .     ,         		
	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
	if(parseFloat(obj.value)>maxValue)
		obj.value=obj.value.substring(0,obj.value.length-1);
}

//      
function checkNoNum(obj){	
	if(obj.value.length>1){
		if(0 == obj.value.substr(0,1) && "." != obj.value.charAt(1)){
			obj.value = obj.value.replace(obj.value,"");
		}
	}
	obj.value = obj.value.replace(/[^\d]/g,"");	
	obj.value = obj.value.replace(/[^\d]/g,"");		
	obj.value = obj.value.replace(/^\./g,"");			
	obj.value = obj.value.replace(/\.{2,}/g,".");		
	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");

}

//      
function checkTel(obj){	
	obj.value = obj.value.replace(/[^\d]/g,"");		
	obj.value = obj.value.replace(/^\./g,"");			
	obj.value = obj.value.replace(/\.{2,}/g,".");			
	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}

function checkMoneyFormat(val){
//	var reg = /^(([1-9]+)|([0-9]+\.[0-9]{0,5}))$/;
	var reg = /^(\d+\.\d{0,5}|\d+)$/;
    var isMoneyFormatRight = reg.test(val);
    return isMoneyFormatRight;
}

function changeTwoDecimal(floatvar){
	var f_x = Math.round(floatvar*100)/100;
	return f_x;
}