目的

javascript 进行字符判断, 用于主机名简写校验

只可以包含小写英文,数字 及 横杠
不支持 数字或横杠开头
不支持横杠结尾

function checkHostName(str){
	if ( str.match(/^[a-z0-9\-]*$/) == null) {
		return false;
	} else {
		if (str.match(/^[a-z]/) == null) {
			return false;
		} else {
			if (str.match(/[\-]$/) != null) {
				return false;
			} else {
				return true;
			}
		}	
	}
}
Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐