Java Code Examples for cn.hutool.core.util.ReUtil#isMatch()

The following examples show how to use cn.hutool.core.util.ReUtil#isMatch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FqWebsiteDirController.java    From feiqu-opensource with Apache License 2.0 5 votes vote down vote up
/**
 * ajax添加FqWebsiteDir
 */
@ResponseBody
@PostMapping("/add")
public Object add(FqWebsiteDir fqWebsiteDir, HttpServletRequest request, HttpServletResponse response) {
    BaseResult result = new BaseResult();
    if(StringUtils.isBlank(fqWebsiteDir.getName()) || StringUtils.isBlank(fqWebsiteDir.getType())){
        result.setResult(ResultEnum.PARAM_NULL);
        return result;
    }

    if(!ReUtil.isMatch(PatternPool.URL,fqWebsiteDir.getUrl())){
        result.setResult(ResultEnum.WEBSITE_URL_ERROR);
        return result;
    }
    FqUserCache fqUserCache = getCurrentUser();
    try {
        FqWebsiteDirExample example = new FqWebsiteDirExample();
        example.createCriteria().andUrlEqualTo(fqWebsiteDir.getUrl()).andDelFlagEqualTo(YesNoEnum.NO.getValue());
        FqWebsiteDir fqWebsiteDirDB = fqWebsiteDirService.selectFirstByExample(example);
        if(fqWebsiteDirDB != null){
            result.setResult(ResultEnum.WEBSITE_URL_EXISTS);
            return result;
        }

        fqWebsiteDir.setDelFlag(YesNoEnum.NO.getValue());
        fqWebsiteDir.setUserId(fqUserCache == null?0:fqUserCache.getId());
        fqWebsiteDir.setCreateTime(new Date());
        fqWebsiteDir.setClickCount(0);
        fqWebsiteDirService.insert(fqWebsiteDir);
        CacheManager.refreshWebsiteCache();
    } catch (Exception e) {
        logger.error("发生系统错误",e);
        result.setResult(ResultEnum.SYSTEM_ERROR);
        return result;
    }
    return result;
}
 
Example 2
Source File: Dc3Util.java    From iot-dc3 with Apache License 2.0 2 votes vote down vote up
/**
 * 判断字符串是否为 用户名格式(2-32)
 *
 * @param name String
 * @return boolean
 */
public static boolean isName(String name) {
    String regex = "^[A-Za-z0-9\\u4e00-\\u9fa5][A-Za-z0-9\\u4e00-\\u9fa5-_]{1,31}$";
    return ReUtil.isMatch(regex, name);
}
 
Example 3
Source File: Dc3Util.java    From iot-dc3 with Apache License 2.0 2 votes vote down vote up
/**
 * 判断字符串是否为 手机号码格式
 *
 * @param phone String
 * @return boolean
 */
public static boolean isPhone(String phone) {
    String regex = "^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$";
    return ReUtil.isMatch(regex, phone);
}
 
Example 4
Source File: Dc3Util.java    From iot-dc3 with Apache License 2.0 2 votes vote down vote up
/**
 * 判断字符串是否为 邮箱地址格式
 *
 * @param mail String
 * @return boolean
 */
public static boolean isMail(String mail) {
    String regex = "^([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+$";
    return ReUtil.isMatch(regex, mail);
}
 
Example 5
Source File: Dc3Util.java    From iot-dc3 with Apache License 2.0 2 votes vote down vote up
/**
 * 判断字符串是否为 密码格式(8-16)
 *
 * @param password String
 * @return boolean
 */
public static boolean isPassword(String password) {
    String regex = "^[a-zA-Z]\\w{7,15}$";
    return ReUtil.isMatch(regex, password);
}
 
Example 6
Source File: Dc3Util.java    From iot-dc3 with Apache License 2.0 2 votes vote down vote up
/**
 * 判断字符串是否为 Host格式
 *
 * @param host String
 * @return boolean
 */
public static boolean isHost(String host) {
    String regex = "^((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})(\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})){3}$";
    return ReUtil.isMatch(regex, host);
}
 
Example 7
Source File: Dc3Util.java    From iot-dc3 with Apache License 2.0 2 votes vote down vote up
/**
 * 判断字符串是否为 驱动端口格式
 *
 * @param port Integer
 * @return boolean
 */
public static boolean isDriverPort(int port) {
    String regex = "^8[6-7][0-9]{2}$";
    return ReUtil.isMatch(regex, String.valueOf(port));
}