-1
Type: abc@def
Must have a (@) in the middle between the seven characters typed.
-1
Type: abc@def
Must have a (@) in the middle between the seven characters typed.
0
An alternative to solve this is to create a validation methods using android.util.Patterns.EMAIL_ADDRESS
. See how it would look:
public static boolean validEmail(CharSequence str) {
return str != null && android.util.Patterns.EMAIL_ADDRESS.matcher(str).matches();
}
To check you can use the method addTextChangeListener
for his EditText
. See 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 about Patterns
in the documentation.
Browser other questions tagged java android edittext
You are not signed in. Login or sign up in order to post.
Very good your answer! But could you tell me where I add these methods and functions? ?
– Realidade Aumentada
@Realityprovided you first to develop Android, you need to have basic concepts of JAVA. On the internet you will find millions of tutorials. However, documentation is basically the best place to learn.
– viana
Thank you very much!!!
– Realidade Aumentada
@Did you manage to implement reality? If the answer was useful, you can validate it if you like. abs
– viana