﻿//只能输入整数
function inputOnlyInt()
{if("0".charCodeAt(0)<=event.keyCode&&event.keyCode<="9".charCodeAt(0)) return true;
       else return false;}

//验证表达式
function FormVerify() {
	this.regDate1 = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
	this.exampleDate1="2009-09-30";
	this.regDate2 = /^(\d{1,4})(\/|\/)(\d{1,2})\2(\d{1,2})$/;
	this.exampleDate2="2009/09/30"; 
	this.regDate3 = /^(\d{1,4})(|\/)(\d{1,2})\2(\d{1,2})$/;
	this.exampleDate3="20090930";
	this.regRequire = /.+/;
	this.regEmail = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	this.regPhone = /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
	this.regMobile = /^(130|131|132|133|134|135|136|137|138|139|150|151|152|153|154|155|156|157|158|159|180|181|182|183|184|185|186|187|188|189)\d{8}$/;
	this.regUrl = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
	this.regIdCard15 = /^\d{15}(\d{2}[A-Za-z0-9])?$/;	
	this.regIdCard18 = /^\d{17}(?:\d|x|X)$/;
	this.regMoney = /[0-9](\.|\/)(\d{2})$/;;
	this.regNumber = /^\d+$/;
	this.regZip = /^[1-9]\d{5}$/;
	this.regQQ = /^[1-9]\d{4,8}$/;
	this.regZInteger= /^[1-9]\d*$/;
	this.regInteger = /^[-\+]?\d+$/;
	this.regDouble = /^[-\+]?\d+(\.\d+)?$/;
	this.regEnglish = /^[A-Za-z]+$/;
	this.regEnglishAndNumber = /^[A-Za-z0-9]+$/;
	this.regChinese =  /^[\u0391-\uFFE5]+$/;
	this.regUnSafe = /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/;
	this.extArray = new Array(".gif",".jpg",".png",".bmp",".xml",".txt",".doc",".xls",".zip",".rar",".pdf",".dbf");
	this.regYearMonth = /^\d{4}[-]\d{2}$/;
	this.regDigital = /(^[0-9]{1,13}\.[0-9]{0,4}$)|(^[0-9]{1,13}$)/;
	this.regPercentDigital = /(^[0-9]{1,3}\.[0-9]{0,2}$)|(^[0-9]{1,3}$)/;
	this.regPercent = "(^[0-9]{1,3}\\.[0-9]{1,@@@}$)|(^[0-9]{1,3}$)";
	this.formNotChar=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/;
	this.emailNotChar=/^[!@#$%\\^&\\*\\(\\)]<>$/;
	this.regPassword=/^[a-zA-Z0-9]{6,15}$/;
	this.regLoginName="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
}
var FormVerify = new FormVerify();

function GetStrLen(str)
{
	var len;
	var i;
	len = 0;
	for (i=0;i<str.length;i++)
	{
		if (str.charCodeAt(i)>255) len+=2; else len++;
	}
	return len;
}
function strlen(str)
{
	var len;
	var i;
	len = 0;
	for (i=0;i<str.length;i++)
	{
		if (str.charCodeAt(i)>255) len+=2; else len++;
	}
	return len;
}
//增加一个去除空格的函数
function Trim(str)
{
    return str.replace(/(^\s*)|(\s*$)/g, "");
}
function isValidUserID(checkStr)
{
	var checkOK = FormVerify.regLoginName;
	var allValid = true;
	for (i=0;i<checkStr.length;i++)
	{
	  ch=checkStr.charAt(i);
	  for(j=0;j<checkOK.length;j++)
	  if(ch==checkOK.charAt(j))
	    break;
	  if(j==checkOK.length)
	   {
	    allValid = false;
	    break;
	   }
	}
	return allValid;
}

function isPassword(checkStr)
{
    var reg=FormVerify.regPassword;
	if (reg.test(checkStr)==false)
	{
        return false;
	}
	else
	{		
        return true;
	}
}

function isEmail(checkStr)
{
    var reg=FormVerify.regEmail;
	if (reg.test(checkStr)==false)
	{
        return false;
	}
	else
	{		
        return true;
	}
}

function isMobile(checkStr)
{
    var reg=FormVerify.regMobile;
	if (reg.test(checkStr)==false)
    {
        return false;
	}
	else
	{		
        return true;
	}
}

function isPhone(checkStr)
{
    var reg=FormVerify.regPhone;
	if (reg.test(checkStr)==false)
	{
        return false;
	}
	else
	{		
        return true;
	}
}

function isUrl(checkStr)
{
    var reg=FormVerify.regUrl;
	if (reg.test(checkStr)==false)
	{
        return false;
	}
	else
	{		
        return true;
	}
}