日期:2014-05-16 浏览次数:20401 次
/* JS验证IP是否合法 */ function isIP(strIP) { var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g; // 匹配IP地址的正则表达式 if(re.test(strIP)) if( RegExp.$1 <256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256) return true; return false; }
?
?
/*Java 验证Ip是否合法*/ public static boolean isIPAddress(String ipaddr) { boolean flag = false; Pattern pattern = Pattern.compile("\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b"); Matcher m = pattern.matcher(ipaddr); flag = m.matches(); return flag; }?