2010. 6. 25. 18:01
package com.util;
import java.util.regex.Pattern;
/**
* 정규식을 이용한 값 체크
*
* @author bbaeggar
*
*/
public class ValidationUtil {
/**
* 일반 전화번호 검증
*
* @param phoneNum
* @return
*/
public static boolean isNomalPhoneNumber(String phoneNum, String separate) {
String regEx = "^\\d{2,3}"+separate+"\\d{3,4}"+separate+"\\d{4}$";
return Pattern.matches(regEx, phoneNum);
}
/**
* 모바일 전화번호 검증
*
* @param phoneNum
* @return
*/
public static boolean isMobilePhoneNumber(String phoneNum, String separate) {
String regEx = "^01(?:[0-9])"+separate+"(?:\\d{3}|\\d{4})"+separate+"\\d{4}$";
return Pattern.matches(regEx, phoneNum);
}
/**
* V4 Ip Address 검증
*
* @param ipAddress
* @return
*/
public static boolean isIpAdressVersion4(String ipAddress) {
String regEx = "([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})";
return Pattern.matches(regEx, ipAddress);
}
/**
* 주민번호 검증
*
* @param ipAddress
* @return
*/
public static boolean isJuminNumber(String number) {
String regEx = "\\d{6}\\-[1-4]\\d{6}";
return Pattern.matches(regEx, number);
}
/**
* 이메일 검증
*
* @param email
* @return
*/
public static boolean isEmail(String email) {
String regEx = "^([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)(\\.[0-9a-zA-Z_-]+){1,2}$";
return Pattern.matches(regEx, email);
}
public static void main(String[] args) {
System.out.println(ValidationUtil.isNomalPhoneNumber("02-123-4516", "-"));
System.out.println(ValidationUtil.isMobilePhoneNumber("016-0014-1234", "-"));
System.out.println(ValidationUtil.isIpAdressVersion4("1.1.1.1"));
System.out.println(ValidationUtil.isJuminNumber("123456-1634316"));
System.out.println(ValidationUtil.isEmail("bbaeggar@gmail.com"));
}
}
import java.util.regex.Pattern;
/**
* 정규식을 이용한 값 체크
*
* @author bbaeggar
*
*/
public class ValidationUtil {
/**
* 일반 전화번호 검증
*
* @param phoneNum
* @return
*/
public static boolean isNomalPhoneNumber(String phoneNum, String separate) {
String regEx = "^\\d{2,3}"+separate+"\\d{3,4}"+separate+"\\d{4}$";
return Pattern.matches(regEx, phoneNum);
}
/**
* 모바일 전화번호 검증
*
* @param phoneNum
* @return
*/
public static boolean isMobilePhoneNumber(String phoneNum, String separate) {
String regEx = "^01(?:[0-9])"+separate+"(?:\\d{3}|\\d{4})"+separate+"\\d{4}$";
return Pattern.matches(regEx, phoneNum);
}
/**
* V4 Ip Address 검증
*
* @param ipAddress
* @return
*/
public static boolean isIpAdressVersion4(String ipAddress) {
String regEx = "([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})";
return Pattern.matches(regEx, ipAddress);
}
/**
* 주민번호 검증
*
* @param ipAddress
* @return
*/
public static boolean isJuminNumber(String number) {
String regEx = "\\d{6}\\-[1-4]\\d{6}";
return Pattern.matches(regEx, number);
}
/**
* 이메일 검증
*
* @param email
* @return
*/
public static boolean isEmail(String email) {
String regEx = "^([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)(\\.[0-9a-zA-Z_-]+){1,2}$";
return Pattern.matches(regEx, email);
}
public static void main(String[] args) {
System.out.println(ValidationUtil.isNomalPhoneNumber("02-123-4516", "-"));
System.out.println(ValidationUtil.isMobilePhoneNumber("016-0014-1234", "-"));
System.out.println(ValidationUtil.isIpAdressVersion4("1.1.1.1"));
System.out.println(ValidationUtil.isJuminNumber("123456-1634316"));
System.out.println(ValidationUtil.isEmail("bbaeggar@gmail.com"));
}
}
'java > util' 카테고리의 다른 글
Calendar, SimpleDateFormat 사용하자 (0) | 2010.06.28 |
---|---|
[replaceAll] - 문자열 치환 (0) | 2010.06.28 |
[java] NumberFormat 을 사용해서 double 가독성 있게 표현하기 (0) | 2010.06.25 |
[정규식] - 한글 검사 (0) | 2010.06.25 |
[정규식] - 초성 검사 (0) | 2010.06.25 |