Android Email Validation on EditText

前端 未结 13 1049
陌清茗
陌清茗 2020-12-29 04:38

I have one edittext and I would to to write email validation in my Editttext this is a xml code



        
相关标签:
13条回答
  • 2020-12-29 05:33
    String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";
    
    
    if(emailId.getText().toString().isEmpty()) {
     Toast.makeText(getApplicationContext(),"enter email address",Toast.LENGTH_SHORT).show();
    else {
    if (emailId.getText().toString().trim().matches(emailPattern)) {
      Toast.makeText(getApplicationContext(),"valid email address",Toast.LENGTH_SHORT).show();
     } else {
      Toast.makeText(getApplicationContext(),"Invalid email address", Toast.LENGTH_SHORT).show();
      }
    }
    
    0 讨论(0)
提交回复
热议问题