260407_02_ENH: String, Numeric 유틸 추가
This commit is contained in:
@@ -5,6 +5,8 @@ public final class StringUtil {
|
||||
private StringUtil() {
|
||||
}
|
||||
|
||||
private static final String BASIC_TEXT_REGEX = "^[가-힣a-zA-Z0-9()_\\-\\[\\] ]+$";
|
||||
|
||||
/** null 또는 "" 인지 */
|
||||
public static boolean isNullOrEmpty(String s) {
|
||||
return s == null || s.isEmpty();
|
||||
@@ -19,4 +21,46 @@ public final class StringUtil {
|
||||
public static boolean hasText(String s) {
|
||||
return s != null && !s.isBlank();
|
||||
}
|
||||
|
||||
public static String normalizeBlank(String raw) {
|
||||
if (raw == null) {
|
||||
return null;
|
||||
}
|
||||
String s = raw.trim();
|
||||
return s.isEmpty() ? null : s;
|
||||
}
|
||||
|
||||
public static String normalizeEmail(String raw) {
|
||||
String s = normalizeBlank(raw);
|
||||
return s == null ? null : s.toLowerCase();
|
||||
}
|
||||
|
||||
public static String normalizeOnlyNumber(String raw) {
|
||||
String s = normalizeBlank(raw);
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
String digits = s.replaceAll("[^0-9]", "");
|
||||
return digits.isBlank() ? null : digits;
|
||||
}
|
||||
|
||||
public static boolean isBasicText(String raw){
|
||||
return isBasicText(raw, BASIC_TEXT_REGEX);
|
||||
}
|
||||
|
||||
public static boolean isBasicText(String raw, String regex){
|
||||
String s = normalizeBlank(raw);
|
||||
if (s == null) {
|
||||
return true;
|
||||
}
|
||||
return s.matches(regex);
|
||||
}
|
||||
|
||||
public static boolean isBasicEmail(String raw) {
|
||||
String s = normalizeBlank(raw);
|
||||
if (s == null) {
|
||||
return true;
|
||||
}
|
||||
return s.matches("^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user