자바 일반
자바 정규식, 한글이 있는지
안드로이
2021. 5. 31. 17:32
자바 정규식, 한글이 있는지, 한글과 영어만 있는지 체크
import java.util.regex.Pattern;
/**
* 문자에 한글이 포함되어 있는지 여부
*
* @param word
* @return
*/
public static boolean isKorChar(String word) {
return Pattern.matches(".*[ㄱ-ㅎㅏ-ㅣ가-힣]+.*", word);
}
/**
* 이메일 주소인지 여부
*
* @param word
* @return
*/
public static boolean isEmaiAddr(String word) {
return Pattern.matches("^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}$", word);
}
/**
* 이름인지 여부 (한글과 영어만 사용)
*
* @param word
* @return
*/
public static boolean isNameCheck(String word) {
return Pattern.matches("^[가-힣a-zA-Z]*$", word);
}