How to create a standard typing format in an Android Studio form?

Asked

Viewed 110 times

-1

Type: abc@def

Must have a (@) in the middle between the seven characters typed.

1 answer

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.

  • Very good your answer! But could you tell me where I add these methods and functions? ?

  • @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.

  • Thank you very much!!!

  • @Did you manage to implement reality? If the answer was useful, you can validate it if you like. abs

Browser other questions tagged

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