用android模式实现电子邮件验证器

时间:2015-07-08 20:57:54

标签: java android validation user-interface

我正在尝试使用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();
        }
    });

1 个答案:

答案 0 :(得分:1)

这个怎么样?

//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();
    }
});