-
[Tip] JAVA 각종 유용한 정규식Mhwan's Develope/JAVA 2016. 10. 25. 22:20이메일 주소 정규식1(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])
cs 휴대폰 번호 정규식 ((010, 011, 016 등) (3자리/4자리) 4자리)
101(?:0|1|[6-9])(?:\d{3}|\d{4})(\d{4})cs IP 주소1((([0-9])|([1-9]\d{1})|(1\d{2})|(2[0-4]\d)|(25[0-5]))\.){3}(([0-9])|([1-9]\d{1})|(1\d{2})|(2[0-4]\d)|(25[0-5]))cs URL 주소
1^(https?):\/\/([^:\/\s]+)(:([^\/]*))?((\/[^\s/\/]+)*)?\/?([^#\s\?]*)(\?([^#\s]*))?(#(\w*))?$cs 사용 방법
1234567891011121314public class DataValidation {public static boolean isValidValue(String value, Type type){if (type.equals(Type.EMAIL))return Pattern.matches(EMAIL_REGEX, value);else if (type.equals(Type.PHONE_NUMBER))return Pattern.matches(PHONE_NUMBER_REGEX, value);return false;}public enum Type { EMAIL, PHONE_NUMBER }private static final String EMAIL_REGEX = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";private static final String PHONE_NUMBER_REGEX = "01(?:0|1|[6-9])(?:\\d{3}|\\d{4})(\\d{4})";}cs 기타 유용한 것들 : http://www.mkyong.com/regular-expressions/10-java-regular-expression-examples-you-should-know/
'Mhwan's Develope > JAVA' 카테고리의 다른 글
[Develop] OS 메모리 할당 알고리즘 (0) 2020.01.03 [Develop] 다중쓰레드로 40x40행렬 곱셈 계산 (0) 2020.01.03 [Tip] 날짜 관련 유용하게 쓰일 변환하는 법 (Using SimpleDateFormat) (0) 2016.11.02 [Tip] 문자열 바이트 세기 (String Text Byte) (0) 2016.10.27