2016-10-05 10 views
-1

私はJavaプログラミングでかなり新しく、この問題に1時間近く対処しています。なぜパスワードの検証で「Passswordにスペースが含まれていますか」と書かれていますか?&と、電子メールアドレス "Javaの電子メールとパスワードの検証

ive私のコードで何度も見ていますが、何かエラーを検出することができません。どんな助けでも大歓迎です。

public boolean validate() { 

    if (email == null) { 
     message = "no email address set"; 
     return false; 
    } 

    if (password == null) { 
     message = "no password set"; 
     return false; 
    } 

    if (!email.matches("\\[email protected]\\.\\+")) { 
     message = "Invalid Email address"; 
     return false; 
    } 

    if (password.length() < 8) { 
     message = "Password must be at least 8 characters"; 
     return false; 
    } 

    // 
    else if (!password.matches("\\w*\\s+\\w*")) { 
     message = "Password cannot contain space"; 
     return false; 
    } 
    return true; 
} 
+0

検証を処理するコードは何ですか? –

答えて

0

あなたはあなたの電子メール以下&パスワード検証を変更する必要があります。

if (!email.matches("\\[email protected]\\.\\+")) { 
    message = "Invalid Email address"; 
    return false; 
} 
// And below 
else if (!password.matches("\\w*\\s+\\w*")) { 
    message = "Password cannot contain space"; 
    return false; 
} 

public static final Pattern VALID_EMAIL_ADDRESS_REGEX = 
     Pattern.compile("^[A-Z0-9._%+-][email protected][A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE); 

public boolean validateEmailId(String emailId) { 
    Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(emailId); 
    return matcher.find(); 
} 

public boolean validate() { 
    //...other conditions as it is 

    //Invalid Email address 
    if(!validateEmailId(email)){ 
     message = "Invalid Email address"; 
     return false; 
    } 

    //Password cannot contain space 
    else if(!Pattern.matches("[^ ]*", password)){ 
    message = "Password cannot contain space"; 
    return false; 
    } 

} 
関連する問題