常用工具类StringUtils

public class StringUtils {

// 两次点击间隔不能少于1000ms
private static final int FAST_CLICK_DELAY_TIME = 2000;
private static long lastClickTime;


public static boolean isFastClick() {
    long time = System.currentTimeMillis();
    long timeD = time - lastClickTime;
    if (0 < timeD && timeD < FAST_CLICK_DELAY_TIME) {
        return true;
    }
    lastClickTime = time;
    return false;
}

/**
 * 钱包地址判断
 */
public static boolean isAddress(String str) {
    if (!str.startsWith("0x") || str.length() != 42) {
        return false;
    }
    return true;
}

/**
 * 手续费
 */
public static String getFee(String str) {
    if (TextUtils.isEmpty(str))return "0";
    BigDecimal lockNum = new BigDecimal(str);
    BigDecimal charge = BigDecimal.valueOf(5);
    if (lockNum.compareTo(BigDecimal.valueOf(1000)) > 0) {
        charge = lockNum.multiply(BigDecimal.valueOf(0.005));
    }
    if (charge.compareTo(BigDecimal.valueOf(25)) > 0) {
        charge = BigDecimal.valueOf(25);
    }
    return charge.toString();
}
public static boolean isboolIp(String ipAddress) {
    String ip = "([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}";
    Pattern pattern = Pattern.compile(ip);
    Matcher matcher = pattern.matcher(ipAddress);
    return matcher.matches();
}
/**
 * 判断字符串是否为空
 *
 * @param str
 * @return
 */
public static boolean isEmpty(String str) {
    if (str == null || str.trim().length() == 0 || "".equals(str)) {
        return true;
    } else {
        return false;
    }
}
/**
 * 解决编码问题,去掉换行
 */
public static String replace(String str) {
    String dest = "";
    if (str != null) {
        Pattern p = Pattern.compile("\t|\r|\n");
        Matcher m = p.matcher(str);
        dest = m.replaceAll("<br/>");
    }
    return dest;
}
/**
 * 将字符串去空格
 *
 * @param str
 * @param defaultStr
 * @return
 */
public static String trimNull(String str, String defaultStr) {
    if (isEmpty(str)) {
        return defaultStr;
    }
    return str.trim();
}

/**
 * 将字符串去掉空格
 *
 * @param str
 * @return
 */
public static String trimNull(String str) {
    return trimNull(str, "");
}

/**
 * 去除小数后面的0
 *
 * @param pricestr
 * @return
 */
public static String trimZero(String pricestr) {
    if (isEmpty(pricestr)) {
        return "0";
    }
    if (pricestr.indexOf(".") > 0) {
        pricestr = pricestr.replaceAll("0+$", "");
        pricestr = pricestr.replaceAll("[.]$", "");
    }

    return pricestr;
}

public static String getDateFormateString(int dateNum) {
    if (dateNum == 0) {
        return "00";
    } else if (dateNum > 0 && dateNum < 10) {
        return "0" + dateNum;
    } else {
        return dateNum + "";
    }
}

/**
 * 验证输入手机号是否合适
 *
 * @param num
 * @return
 */
public static boolean istelphonenum(String num) {
    Pattern phonePattern = Pattern.compile("^[1][3,4,5,6,7,8][0-9]{9}$");
    Matcher matcher = phonePattern.matcher(num);
    if (matcher.find()) {
        return true;
    }
    return false;
}

/**
 * 验证邮箱
 *
 * @param email
 * @return
 */
public static boolean checkEmail(String email) {
    boolean flag = false;
    try {
        String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(email);
        flag = matcher.matches();
    } catch (Exception e) {
        flag = false;
    }
    return flag;
}

/**
 * 校验密码强弱,必须数字和字母组合
 *
 * @param pwd
 * @return
 */
public static boolean checkPwd(String pwd) {
    boolean flag = false;
    try {
        String check = "^.*(?=.{6,15})(?=.*\\d)(?=.*[A-Za-z]).*$";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(pwd);
        flag = matcher.matches();
    } catch (Exception e) {
        flag = false;
    }
    return flag;
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值