JAVA를 JAVA라

[JAVA] 이메일 체크 본문

JAVA/풀어봅시다 (eclipse)

[JAVA] 이메일 체크

샛별KIM 2021. 6. 4. 14:15
package jun04;

import java.util.Scanner;

public class Emailcheck {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String email, id = null, server = null;
		boolean chk = false;

		A: do {
			System.out.println("이메일을 입력하세요.");
			email = sc.next();
			if (!email.contains("@")) {
				System.out.print("올바른 ");
				continue;
			}

			id = email.substring(0, email.indexOf('@'));
			server = email.substring(email.indexOf('@') + 1);

			if (id.length() > 10 || id.length() < 5) {
				System.out.println("ID는 5~10자 이어야 합니다.");
				continue;
			} else if (!(Character.isUpperCase(id.charAt(0)))) {
				System.out.println("ID 첫 글자는 영어 대문자여야 합니다.");
				continue;
			} else {
				for (int i = 1; i < id.length(); i++) {
					if ( Character.isDigit(id.charAt(i)) 
						|| Character.isLowerCase(id.charAt(i))
						|| Character.isUpperCase(id.charAt(i)) ) {
					} else {
						System.out.println("ID는 영문자와 숫자로만 입력할 수 있습니다.");
						continue A;
					}
				}
				System.out.println("올바른 ID입니다.");
				chk = true;
			}

		} while (!chk);

		System.out.println(id);
		System.out.println(server);
	}
}
Comments