function trim(s){
	return s.replace(/^\s*/,"").replace(/\s*$/,"");
}

function fLen(Obj){
	  var nCNLenth = 0;
	  var nLenth = Obj.length;
	  for (var i=0; i<nLenth; i++){
	    if(Obj.charCodeAt(i)>255){
	      nCNLenth += 2; 
	    }else{
	      nCNLenth++;
	    }
	  }
	  return nCNLenth;
	}

function isUsername( username ){
	if( /^\d.*$/.test( username ) ){
		//用户名不能以数字开头
		return 1;
	}
	
	if(! /^\w+$/.test( username ) ){
		//由数字、26个英文字母或者下划线组成的字符串 
		return 3;
	}
	
	if(! /^([a-z]|[A-Z])[0-9a-zA-Z_]+$/.test( username ) ){
		//用户名只能包含_,英文字母，数字
		return 4;
	}
	
	if(fLen( username )<6 || fLen( username )>20 ){
		//合法长度为6-18个字符
		return 2;
	}
	
	return 0;
}

