當我給驗證,以IT領域不驗證正確。 當字段爲空時,它只顯示紅色標記不顯示錯誤,當我點擊edittext時,它會顯示錯誤。驗證領域EDITTEXT Android中
nameValidate = "^[A-Za-z\\s]{1,}[\\.]{0,1}[A-Za-z\\s]{0,}$";
mobile = "^[2-9]{2}[0-9]{8}$";
passwordpattern = "((?=.*[a-z])(?=.*\\d)(?=.*[A-Z])(?=.*[@#$%!]).{8,40})";
//registration button code
btn_registration = (Button) findViewById(R.id.buttonRegister);
btn_registration.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
uname = edittext_username.getText().toString();
password = edittext_Password.getText().toString();
phone = edittext_phone.getText().toString();
if (uname.equals("") || uname.length() <= 3 || uname != nameValidate) {
if (uname.equals("")) {
edittext_username.setError("Name cannot be Blank");
} else {
edittext_username.setError("Enter Valid Name");
}
}
//Toast.makeText(getApplicationContext(), "Please enter username upto 6char", 1000).show();
if (password.equals("") || password.length() < 3) {
// Toast.makeText(getApplicationContext(), "please enter password upto 6char ", 1000).show();
edittext_Password.setError("Password cannot be blank");
}
if (phone.equals("") || phone.length() < 10) {
edittext_phone.setError("Invalid mobile number");
//Toast.makeText(getApplicationContext(), "please entermobile number must be 10 digit", 1000).show();
}
if (uname == null && uname.equals(nameValidate) || password == null || phone == null) {
confirmOtp();
}
}
});
}
其Android版本你測試嗎? –