Email validation

Asked

Viewed 1,531 times

1

How do I make this edittext only valid for an email? It 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();

1 answer

4


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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.