Mastering Development

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?


public class registerForm extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {

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

    idUsername = (EditText) findViewById(;
    idCustomerCode = (EditText) findViewById(;
    idPass = (EditText) findViewById(;

    Button btnRegister = (Button)findViewById(;

    btnRegister.setOnClickListener(new View.OnClickListener() {
        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());



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


Leave a Reply

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