Problem in Implementing EditText field must contains alphanumeric

I have an EditText here called “idCustomerCode”, which used to input a code ID from user, which MUST contains alphanumeric on every input, for example (“abc123”), and will show error messages if it doesn’t meet the criteria. (example : not contains alphabet / numeric (“abcd” or “1234” only), or contains symbol). I have no idea how to implement it into Android Studio.

Examples of Error Message popup :

Customer Code must only contain text and number

Can anyone help me with this code?

Thanks!

public class registerForm extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register_form);

    final EditText idUsername;
    final EditText idCustomerCode;
    final EditText idPass;



    idUsername = (EditText) findViewById(R.id.idUsername);
    idCustomerCode = (EditText) findViewById(R.id.idCustomerCode);
    idPass = (EditText) findViewById(R.id.idPass);

    Button btnRegister = (Button)findViewById(R.id.btnRegister);

    btnRegister.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent;
            intent = new Intent(getApplicationContext(),loginForm.class);
            intent.putExtra("idUsername", idUsername.getText().toString());
            intent.putExtra("idCustomerCode", idCustomerCode.getText().toString());
            intent.putExtra("idPass", idPass.getText().toString());
            startActivity(intent);
        }
    });

}

}

By the way, I also add this code to my xml, so the idCustomerCode EditText only accept alphanumeric :

android:digits="0123456789qwertzuiopasdfghjklyxcvbnm"

Leave a Reply

Your email address will not be published. Required fields are marked *