﻿
//检查非法字符
String.prototype.isSafe=function(){ 
    if(!this){return false;}
    var teststr=/.*[@~#\$%\^&\*\(\)\+\|\{}"'><].*/i
    return !teststr.test(this); 
}

//String.prototype.length=function(){  
//    return this.replace(/[\u00B5-\uFFE5\uF900-\uFA2D]/g,"**").length;  
//}
//取得含有中文字符的长度
String.prototype.lengthCN=function(){ 
    if(!this){return 0;}
    return this.replace(/[^\x00-\xff]/g,"**").length; 
}
//前后去空格
String.prototype.trim=function(){   
     if(!this){return '';}
     return this.replace(/(^[  \s\u3000]*)|([  \s\u3000]*$)/g, "");  
}
//判断是否是数字
String.prototype.isNumber=function(){ 
 if(!this){return false;}
 return /^\d+$/.test(this)
}
//判断是否是日期
String.prototype.isDate=function(){ 
 if(!this){return false;}
 var ar;
if(this.match(/^\d{4}\-\d\d?\-\d\d?$/)){
 ar=this.replace(/\-0/g,"-").split("-");
}else if(this.match(/^\d{4}\/\d\d?\/\d\d?$/)){
 ar=this.replace(/\/0/g,"/").split("/");
}else {return false;}

ar=new Array(parseInt(ar[0]),parseInt(ar[1])-1,parseInt(ar[2]));
var d=new Date(ar[0],ar[1],ar[2]);
return d.getFullYear()==ar[0] && d.getMonth()==ar[1] && d.getDate()==ar[2];
}
String.prototype.isEmail=function(str){   
		var mail=str;   
		var t=/^\w+@\w+(\.\w+)+/;   
	  var g=/^\w+\.\w+@\w+(\.\w+)+/;   
		if(t.test(mail)==false && g.test(mail)==false){ 
			return false;   
		}
		return true;
	}
function $(id){
if(document.getElementById('ctl00_ContentPlaceHolder1_'+id)){
return document.getElementById('ctl00_ContentPlaceHolder1_'+id);
}else{
return document.getElementById(id);
}
}
function String.prototype.trim()  
{   if(!this){return '';}
    return this.replace(/(^[  \s\u3000]*)|([  \s\u3000]*$)/g, "");  
}
var CheckCommon = new function(){ 
this.CheckEmpty=function(str,suggestion){
		var CheckStr=$(str).value.trim();
		if(CheckStr==""){
			alert(suggestion);
			if($(str).tagName=="SELECT"){
			$(str).focus();
			}else{
			$(str).select();
			}
			return false;
		} 
		return true;  
	}
	this.CheckEmail=function(str,suggestion){
		var CheckStr=$(str).value.trim();
		if(CheckStr!=""&&CheckStr.isEmail()){
			alert(suggestion);
			$(str).select();
			return false;
		} 
		return true;  
	}
		this.CheckDate=function(str,suggestion){
		var CheckStr=$(str).value.trim();
		if(CheckStr!=""&&!CheckStr.isDate()){
			alert(suggestion);
			$(str).select();
			return false;
		} 
		return true;  
	}
	this.CheckNum=function(str,suggestion,iNum){
		var CheckStr=$(str).value.trim();
		if(iNum){
		    if(CheckStr!=""&&!/^\d+(\.[0-9]{0,iNum})?/.test(CheckStr)){
			    alert(suggestion);
			    $(str).select();
			    return false;
		    } else{return true;}
		}
		if(CheckStr!=""&&!CheckStr.isNumber()){
			alert(suggestion);
			$(str).select();
			return false;
		} 
		return true;  
	}
	this.CheckPhone=function(str,suggestion){
		var CheckStr=$(str).value.trim();
		var reg=/(^0[0-9]{2,3}(\-)?[0-9]{7,8}$)|(^(130|131|132|133|134|135|136|137|138|139|150|151|152|153|154|155|156|157|158|159)[0-9]{8}$)/g

		if(CheckStr!=""&&!reg.test(CheckStr)){
			alert(suggestion);
			$(str).select();
			return false;
		} 
		return true;  
	}
	this.CheckMaxInput=function(str,MaxLen,suggestion){
	if($(str).value.length > (MaxLen-1)){
					$(str).value = $(str).value.substring(0, MaxLen);
					alert(suggestion);
					$(str).select();
					return  false;
				}
	return true;
	}
	
	}