Name validation
Name validation 추가
This commit is contained in:
@@ -0,0 +1,48 @@
|
|||||||
|
package com.kamco.cd.kamcoback.common.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class NameValidator {
|
||||||
|
|
||||||
|
private static final String HANGUL_REGEX = ".*\\p{IsHangul}.*";
|
||||||
|
private static final Pattern HANGUL_PATTERN = Pattern.compile(HANGUL_REGEX);
|
||||||
|
|
||||||
|
private static final String WHITESPACE_REGEX = ".*\\s.*";
|
||||||
|
private static final Pattern WHITESPACE_PATTERN = Pattern.compile(WHITESPACE_REGEX);
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean containsKorean(String str) {
|
||||||
|
if (str == null || str.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Matcher matcher = HANGUL_PATTERN.matcher(str);
|
||||||
|
return matcher.matches();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean containsWhitespaceRegex(String str) {
|
||||||
|
if (str == null || str.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher matcher = WHITESPACE_PATTERN.matcher(str);
|
||||||
|
// find()를 사용하여 문자열 내에서 패턴이 일치하는 부분이 있는지 확인
|
||||||
|
return matcher.find();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNullOrEmpty(String str) {
|
||||||
|
if (str == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user