日期:2014-05-20 浏览次数:20640 次
//==============================================================================
//
// @author Slive
// @date 2013-6-18
//
//==============================================================================
package org.slive.validator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* ValidatorUtil supplies many ordinary validation functions,such as:<br/>
* <ul>
* <li> ipv4 address validate
* <li> device mac address validate
* </ul>
* @author Slive
*/
public class ValidateUtil
{
public static final String IPV4_REGEX = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";
public static final String MAC_REGEX = "([0-9A-Fa-f]{2})(-[0-9A-Fa-f]{2}){5}";
public static final String R_1_65535_REGEX = "([1-9](\\d{0,3}))|([1-5](\\d{4}))|(6553[0-5])|(655[0-2]\\d)|(65[0-4](\\d{2}))|(6[0-4](\\d{3}))";
public static final String IPV4_PORT_REGEX = IPV4_REGEX + "(\\/)" + R_1_65535_REGEX;
public static final String UDP_IPV4_PORT_REGEX = "([uU][dD][pP])(\\:)" + IPV4_PORT_REGEX;
public static final String TCP_IPV4_PORT_REGEX = "([tT][cC][pP])(\\:)" + IPV4_PORT_REGEX;
/**
* Legal ipv4 address follow as: "xxx(1-255).xxx.xxx.xxx(0-255)"
* @param ipv4 ipv4 address
* @return if ipv4 is null, it will return false;
* @see #IP_REGEX
*/
public static boolean ipV4Validate(String ipv4){
return ipv4Validate(ipv4,IPV4_REGEX);
}
/**
* Legal device mac address follow as: "xx-xx-xx-xx-xx(0-9a-f)"
* @param mac device mac address
* @return if mac is null, it will return false;
* @see #MAC_REGEX