2014-03-31 2 views
0

내부 검증이 코드 나는 이미 그 :이메일 내가 글고 내부에 도입 된 이메일을 확인하려는 글고

public static boolean isValidEmail(String str) { 
    boolean isValid = false; 
    String expression = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; 
    CharSequence inputStr = str; 
    Pattern pattern = Pattern.compile(expression); 
    Matcher matcher = pattern.matcher(inputStr); 
    if (matcher.matches()) { 
     isValid = true; 
    } 
    return isValid; 
} 

문제는 내가 _ 사용하고 때이다 - 이러한 문자를 이메일의 시작에 id, 오류는 보이지 않지만 다른 문자를 사용하면 오류가 표시됩니다.

이제 이메일 ID를 시작할 때 특수 문자를 사용하면 오류가 표시되어야합니다. 이메일 ID 시작시 특수 문자를 사용할 수 없습니다.

이걸 위해해야 ​​할 일은 무엇입니까?

android.util.Patterns.EMAIL_ADDRESS 
+0

'amardeep @ your-company.com'도 유효한 이메일 ID입니다. –

+0

[http://www.mkyong.com/regular-expressions/how-to-validate-email-address-with-regular-expression/](http://www.mkyong.com/regular-expressions/how- to-validate-email-address-with-regular-expression /) –

+0

@RethinavelPillai [email protected] 또는 [email protected]을 사용할 때 오류가 표시되지 않습니다. – Amardeepvijay

답변

1

이 간단한 코드를 시도 입력을 수락하기 전에 메소드를 작성하고 확인하기 만하면됩니다. 이메일 입력 문자 안드로이드의 수동 검사가 필요 등 단지

처럼 전화를 그냥 버튼 내에서 OnCreate 경우, 또는 그런 예

public static boolean isEmailValid(CharSequence email) 
    { 
     return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches() ; 

    } 

를 호출 할 필요가 정의 된 모든 데이터 유형이있다 없습니다

EditText et = (EditText)findViewbyid(R.id.email) ; 
String em = et.getText().toString() ; 
if(!Validating.isEmailValid(em)) 
     { 
     et.setHint("use this format [email protected]") ; 
      return; 
     } 
+0

%[email protected] 이메일 ID를 사용했을 때 표시된 오류가 있지만 [email protected] 및 [email protected]을 사용할 때 오류가 표시되지 않습니다. – Amardeepvijay

+0

@Amardeep 특수 기호가 주소에 있습니다. 시스템 전자 메일에 오류가 발생할 수있는 것은 좋지 않습니다. 그러나 정말로 필요한 경우 다음 그룹과 같이 사용 가능한 문자 목록을 정의 할 수 있습니다. "^ [(a-zA-Z-0-9 - \\ u0025 \\\ _ \\ + \\.)] + @ [(azAz)] + \\. [(a-zA-z)] {2,3} $ " –

+0

이메일 아이디에 특수 문자를 사용하고 싶지 않습니다. 내가 특수 문자를 사용했을 때 그 오류를 보여 주었지만 _과 -를 사용할 때. 오류 메시지가 표시되지 않음 – Amardeepvijay

1

안드로이드 SDK의 이메일 주소를 확인하는 데 사용 패턴은

public static final Pattern EMAIL_ADDRESS 
     = Pattern.compile(
      "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" + 
      "\\@" + 
      "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + 
      "(" + 
       "\\." + 
       "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + 
      ")+" 
     ); 

당신이 이런 식으로 액세스 할 수 있습니다 :

0

:

public static boolean validateEmailAddress(String emailAddress) {  
     regexPattern = Pattern .compile("^[(a-zA-Z-0-9-\\_\\+\\.)][email protected][(a-z-A-z)]+\\.[(a-zA-z)]{2,3}$"); 
     regMatcher = regexPattern.matcher(emailAddress); 
     if (regMatcher.matches()) 
      { 
      return true; 
     } else { 
      return false; 
     } 
     }