Type: abc @ def
Must have an (@) in the middle of the seven characters entered.
Type: abc @ def
Must have an (@) in the middle of the seven characters entered.
An alternative to resolve this is to create a validation method using android.util.Patterns.EMAIL_ADDRESS
. Here's how it would look:
public static boolean validEmail(CharSequence str) {
return str != null && android.util.Patterns.EMAIL_ADDRESS.matcher(str).matches();
}
To verify you can use the addTextChangeListener
method for your EditText
. Here's how it would look:
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if(validEmail(s))
Toast.makeText(MainActivity.this, ""+s,Toast.LENGTH_LONG).show();
else Log.wtf("TAG","ERRO");
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
See more details on in documentation .