Post

정규표현식 정리

상황 별 정규 표현식 정리

전화번호

1
2
3
4
5
6
	@Test
	void account_tel_test_2() {
		String tel = "010-1234-5678";
		boolean result = Pattern.matches("^01([0|1|6|7|8|9])-?(\\d{3,4})-?(\\d{4})$", tel);
		log.info("[*] -> {}", result);
	}

이메일

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
	@Test
	void email_test_2() {
		// 숫자, 영어로 시작하고
		// -_. 을 포함한 숫자, 영어만 존재하며
		// @ 가 존재한다.
		// 숫자, 영어로 다시 시작하고
		// -_. 포함한 영어, 숫자만 존재하고
		// . 이 들어간다.
		// 2 혹은 3 글자인 영어로 끝난다.

		String email = "fjwief-fw@nate.com";
		boolean result = Pattern.matches(
				"^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}$",
				email
		);
		log.info("[*] -> {}", result);
	}
This post is licensed under CC BY 4.0 by the author.