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

-1

Type: abc @ def

Must have an (@) in the middle of the seven characters entered.

    
asked by anonymous 27.01.2017 / 03:22

1 answer

0

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 .

    
27.01.2017 / 03:46