我试图在我的应用程序中实现电子邮件验证,使用android模式,但每次当我调用我的函数isEmailValid(String)
时都没有返回。
有人能帮忙吗?
//Valida conteúdo do email
char_Email.setOnFocusChangeListener(new View.OnFocusChangeListener(){
@Override
public void onFocusChange(View v, boolean hasFocus){
if(!hasFocus){
email = char_Email.getText().toString();
isEmailValid(email);
}
}
private boolean isEmailValid(String email){
return Patterns.EMAIL_ADDRESS.matcher(email).matches();
}
});
这个怎么样?
//Valida conteúdo do email
char_Email.setOnFocusChangeListener(new View.OnFocusChangeListener(){
@Override
public void onFocusChange(View v, boolean hasFocus){
if(!hasFocus){
email = char_Email.getText().toString();
boolean validEmail = isEmailValid(email);
if(!validEmail) {
// Do something, maybe show a Toast
}
}
}
private boolean isEmailValid(String email){
return Patterns.EMAIL_ADDRESS.matcher(email).matches();
}
});