正则表达式判断IP合法

//验证IP是否合法
	obj=document.getElementById("ip").value
	if(obj!=""){
		var exp=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
		var reg = obj.match(exp);
		if(reg==null)
		{
		alert("IP地址不合法!");
		return false;
		}
	}

相关推荐