Email validation [duplicate]

0

How to make this edittext only valid for an email? That contains for example [email protected] that contains at least the "@"?

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cadastro);


        email = (EditText) findViewById(R.id.Cemail);


      btnfincad.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mEmail = email.getText().toString();
    
asked by anonymous 12.07.2017 / 14:41

1 answer

2

You can use a method like the one below, if what you're looking for is just to validate the format.

private boolean validateEmailFormat(final String email) {
   if (android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
        return true;
    }
    return false;
}
    
17.07.2017 / 19:53