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;
}
}