js判断IP字符串是否正确
//判断ip地址的合法性 function checkIP(value){ 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 = value.match(exp); if(reg==null) { alert("开始的IP地址不合法!"); return false; } } //比较两个ip地址的前后,,如果大于,返回1,等于返回0,小于返回-1 function compareIP(ipBegin, ipEnd) { var temp1; var temp2; temp1 = ipBegin.split("."); temp2 = ipEnd.split("."); for (var i = 0; i < 4; i++) { if (temp1[i]>temp2[i]) { return 1; } else if (temp1[i]<temp2[i]) { return -1; } } return 0; }
原文来自:http://www.cnblogs.com/shenliang123/archive/2012/04/17/2453577.html