mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-06-11 10:49:52 +08:00
新增工具类
This commit is contained in:
@@ -5,6 +5,8 @@ import com.jsowell.common.core.text.StrFormatter;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 字符串工具类
|
||||
@@ -515,20 +517,15 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
*/
|
||||
public static String byteArray2HexString(byte[] arrBytes, int count, boolean blank) {
|
||||
String ret = "";
|
||||
if (arrBytes == null || arrBytes.length < 1)
|
||||
return ret;
|
||||
if (count > arrBytes.length)
|
||||
count = arrBytes.length;
|
||||
if (arrBytes == null || arrBytes.length < 1) return ret;
|
||||
if (count > arrBytes.length) count = arrBytes.length;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ret = Integer.toHexString(arrBytes[i] & 0xFF).toUpperCase();
|
||||
if (ret.length() == 1)
|
||||
builder.append("0").append(ret);
|
||||
else
|
||||
builder.append(ret);
|
||||
if (blank)
|
||||
builder.append(" ");
|
||||
if (ret.length() == 1) builder.append("0").append(ret);
|
||||
else builder.append(ret);
|
||||
if (blank) builder.append(" ");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
@@ -558,4 +555,36 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是不是电子邮箱
|
||||
*
|
||||
* @param email
|
||||
* @return
|
||||
*/
|
||||
public static boolean isEmail(String email) {
|
||||
if (email == null || email.length() < 1 || email.length() > 256) {
|
||||
return false;
|
||||
}
|
||||
Pattern pattern = Pattern.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
|
||||
return pattern.matcher(email).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证是否是正确合法的手机号码
|
||||
*
|
||||
* @param phoneNumber
|
||||
* @return 合法返回true,不合法返回false
|
||||
*/
|
||||
public static boolean isPhoneNumber(String phoneNumber) {
|
||||
if (phoneNumber == null || phoneNumber.length() < 1 || phoneNumber.length() > 11) {
|
||||
return false;
|
||||
}
|
||||
Pattern pattern = Pattern.compile("^1[3,4,5,6,7,8,9]\\d{9}$");
|
||||
Matcher matcher = pattern.matcher(phoneNumber);
|
||||
if (matcher.matches()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user