"회원가입페이지"
사용하실 아이디:(단, 특수문자 사용불가)
패스워드:(8자이상, 첫글자 문자, 대소문자와 숫자 조합)
생년월일:991231
회원가입되셨습니다. or 실패하셨습니다 다시 입력하십시오
(패스워드 입력중 대문자만 8자이상인 경우 오류)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
public class Ex06 {
    public static void main(String[] args) {        
        Scanner sc = new Scanner(System.in);
        String id, pass, birth;
 
        System.out.println("**********회원가입**********");
 
        int count = 0;
        for (int i = 0; i < 5; i++) {
            System.out.print("사용하실 아이디(단, 특수문자 사용불가): ");
 
            id = sc.nextLine().trim(); // 앞뒤공간제거후 입력받는다
            char[] ch = new char[id.length()];
 
            for (int j = 0; j < id.length(); j++) {
                ch[j] = id.charAt(j);
                if (!(Character.isDigit(ch[j])) && !(Character.isLetter(ch[j])) && Character.isDefined(ch[j])) { 
                    // 숫자가 아니고, 문자가아니고, 유니코드인 경우(특수문자)
                    count++;
                }
            }
        
            if (count > 0) {
                System.out.println("실패하셨습니다. 다시 입력하십시요.");
                count=0;
            } else {
                System.out.println("아이디 " + id + " 사용하셔도 좋습니다.");
                break;
            }
            if(i==4){
                System.out.println("다시 처음부터 시작하십시오");
                return;
            }
 
        }// for end
 
        for (int i = 0; i < 5; i++) {
            System.out.print("패스워드: ");
            pass = sc.nextLine().trim(); // 패스워드 입력
            int m = password(pass);
            if (m == 0) {
                break;
            } // 리턴이 0이면 반복문종료
            
            if(i==4){
                System.out.println("다시 처음부터 시작하십시오");
                return;
            }
 
        }// for end
 
        System.out.print("생년월일(ex.901231): ");
        birth = sc.nextLine().trim();
        Birth(birth);
 
 
    }//main end
 
    public static int password(String pass){
        char[] ch = new char[pass.length()];
        int count=0;
        for(int i=0;i<pass.length();i++){
            count=0;
            ch[i] = pass.charAt(i);
            if(!(Character.isUpperCase(ch[i]))){
                count++;
            }else if(Character.isLowerCase(ch[i])){
                count++;
            }else if(Character.isDigit(ch[i])){
                count++;
            }else{
                break;
            }
        }
        if(count>0){
            System.out.println("대문자 소문자 숫자로 조합을 하셔야 합니다.");
            return 1;
        }
        
        if(Character.isDigit(ch[0])){
            System.out.println("첫글자는 문자이여야 합니다.");
            return 1;
        }
        if(pass.length()<8){
            System.out.println("8자 이상이여야 합니다.");
            return 1;
        }
        return 0;
    }//password end
    
    public static void Birth(String birth){
        if(Character.isDigit(Integer.parseInt(birth)) || (birth.length()!=6)){
            System.out.println("잘못입력하셨습니다.");
        }else{
            System.out.println("회원가입되셨습니다.");
            
        }
    }
}//class end
cs

결과


다른소스(아이디 입력중 가운데 특수문자가 들어갈 경우 오류)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.util.Scanner;
 
public class Ex03 {
    static final String bar="----------------------------------------------";
    static String[] prn={"사용하실 아이디:","패스워드:","생년월일:"};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean[] result =null;
        String[] input = new String[3];
        System.out.println(bar);
        System.out.println("회원가입페이지");
        System.out.println(bar);
        while(true){
            result =new boolean[]{falsefalsefalse};
            System.out.print(prn[0]);
            input[0]=sc.nextLine();
            char[] ch1 = input[0].toCharArray();
            for(int i=0; i<ch1.length; i++){
                char temp = ch1[i];
                if(Character.isDigit(temp)
                        ||Character.isUpperCase(temp)
                        ||Character.isLowerCase(temp)){
                }else{
                    break;
                }
                result[0]=true;
            }
            System.out.print(prn[1]);        //패스워드
            input[1]=sc.nextLine();
            if(input[1].length()>7&&Character.isLetter(input[1].charAt(0))){
                boolean[] two ={falsefalsefalse};
                for(int i=0; i<input[1].length(); i++){
                    if(Character.isDigit(input[1].charAt(i))){
                        two[2]=true;//숫자검사
                    }
                    if(Character.isUpperCase(input[1].charAt(i))){
                        two[0]=true;// 대문자검사
                    }
                    if(Character.isLowerCase(input[1].charAt(i))){
                        two[1]=true;// 소문자 검사
                    }
//                    System.out.println(two[0]+":"+two[1]+":"+two[2]);
                }
                if(two[0]&&two[1]&&two[2]){
                    result[1]=true;
                }
            }
            System.out.print(prn[2]);
            input[2]=sc.nextLine();
            ch1 = input[2].toCharArray();
            if(ch1.length==6){
                result[2]=true;
            }
            for(int i=0; i<ch1.length; i++){
                if(!(Character.isDigit(ch1[i]))){
                    result[2]=false;
                    break;
                }
            }
            if(result[0]&&result[1]&&result[2]){break;}
            if(!result[0]){
                System.out.println("아이디 입력을 확인하세요");
            }
            if(!result[1]){
                System.out.println("패스워드 입력을 확인하세요");
            }
            if(!result[2]){
                System.out.println("생년월일 입력을 확인하세요");
            }
        }
            System.out.println("회원가입되셨습니다");
    }
 
}
cs

결과


'* Programming > JAVA' 카테고리의 다른 글

DAY16 상속1  (0) 2016.07.26
DAY16 접근제한자  (0) 2016.07.26
DAY15 Wrapper class  (0) 2016.07.25
DAY15 String " "기준으로 불러오기  (0) 2016.07.25
DAY14 Lotto(객체지향)  (0) 2016.07.25

+ Recent posts