// Check the text word length
// The parameter: length, the requirement length
function checkWordLength(length, words) {
	if (words.length > length) {		
		return false;
	}
	else {
		return true;
	}
}

//匹配如下的规则
//1 至少一个"."
//2 有且只有一个"@"
//3 "@"后面至少一个"."
//4 "@"之前支持除了字母和数字外，还包括"_" "-" "."
//5 "@"之后支持除了字母和数字外，还包括"-"
//6 域名最长不能超过63个字符，且“-”不能出现在字符串的最前或最后
//7.统一转换成小写
//@Param emailObject html对象元素，不是具体的value.
function checkEmail( emailObject) {
        var email = emailObject.value;
        email = email.trim();
        if(email.length > 63) {
          return false;
        }
        var emailPattern = /^[A-Za-z0-9]+[\w|\.|\-|_]*@[\w|\-]+(\.)[\w|\-|\.]*[^-]$/;
        if (!email.match(emailPattern)&&email!="") {
              return false;
        }
        else {
              emailObject.value = email.toLowerCase(); //转换成小写
              return true;
        }
}

//Match mobile numbers which starts with 13 or 15,and has 11 numerals.
function checkMobile( mobileNum) {
       	
		var mobilePattern = /^(13|15)\d{9}$/;
        if (!mobileNum.match(mobilePattern) && mobileNum!="") {
               return false;
        } else {
               return true;
        }
}

// 全角转半角函数
function CtoH(obj) {
	var str = obj.value;
	var result = "";
	for (var i = 0; i < str.length; i++) {
		if (str.charCodeAt(i) == 12288) {
			result += String.fromCharCode(str.charCodeAt(i) - 12256);
			continue;
		}
		if (str.charCodeAt(i) > 65280 && str.charCodeAt(i) < 65375) {
			result += String.fromCharCode(str.charCodeAt(i) - 65248);
		} else {
			result += String.fromCharCode(str.charCodeAt(i));
		}
	}
	obj.value = result;
}

//Check a url 
//Match example: http://www.baidu.com | https://www.baidu.com | www.baidu.com 
function isUrl(url) {
    var regExp = /^((http[s]?|ftp):\/\/)?[^\/\.]+?\..+\w$/i;
    if (url.match(regExp)) {
        return true;
    } else {
        return false;
    }      
}

String.prototype.trim  =  function()
{
    return  this.replace(/(^\s*)|(\s*$)/g,  "");
}

