﻿//检查字符串是否为数值
function isNumber( str ){
 	if( str.length == 0 ) return false;
 	for( var loc=0; loc<str.length; loc++ )
 		if( (str.charAt(loc) < '0') || (str.charAt(loc) > '9') ) return false;
 	return true;	
}
 	
//删除字符串前后的空白
function trim(strText){ 
  while (strText.substring(0,1) == ' ') 
    strText = strText.substring(1, strText.length);
  while (strText.substring(strText.length-1,strText.length) == ' ')
    strText = strText.substring(0, strText.length-1);
  return strText;
} 

//检验电子邮件地址是否合法
function isEmail(email) {
	var endvalue,allowstrlist;
	endvalue=true;
	if (email.lastIndexOf("@")==-1 || email.lastIndexOf(".")==-1) {
		endvalue=false;
	}
	if (email.indexOf("@",email.indexOf("@")+1)!=-1 || email.indexOf(".",email.indexOf("@"))==-1) {
		endvalue=false;
	}
	if (email.substr(0,1)=="@" || email.substr(0,1)=="." || email.substr(email.length-1,1)=="@" || email.substr(email.length-1,1)==".") {
		endvalue=false;
	}
	allowstrlist="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.@";
	for (i=0;i<email.length;i++) {
		if (allowstrlist.indexOf(email.substr(i,1))==-1) {
			endvalue=false;
			break;
		}
	}

	return(endvalue);
}
