3 回答

TA貢獻1859條經驗 獲得超6個贊
您當前的實施是驗證來自的輸入editTextUsername并嘗試驗證輸入是否是有效的電子郵件地址。如果您不希望這樣,只需在您的代碼中刪除針對此特定視圖的驗證,如下所示。
public boolean validate() {
boolean valid = false;
//Get values from EditText fields
String userName = editTextUsername.getText().toString();
String Password = editTextPassword.getText().toString();
// Handle the validation for the user name.
// Let us assume, you just want to validate that the user has put something as a user name
if(userName.length() > 0) {
valid = true;
textInputLayoutUsername.setError(null);
} else {
valid = false;
textInputLayoutUsername.setError("Please provide the user name.");
}
}
您可以隨時更改驗證邏輯。我只是舉了一個例子。希望對您有所幫助!

TA貢獻1810條經驗 獲得超4個贊
只需使用純文本字段并在后端代碼 ( [A-Za-z0-9]* ) 中使用正則表達式來驗證您的輸入。
//it's saying if email contains alpnum char and ._- of length min 3 i.e >=3 then its true
if(Email.matches(^[a-zA-Z0-9._-]{3,}$)) {
// valid input code
} else {
// invalid input code
}

TA貢獻1712條經驗 獲得超3個贊
請檢查打擊代碼。
公共布爾驗證(){
//Get values from EditText fields
String userName = editTextUsername.getText().toString().trim();
String Password = editTextPassword.getText().toString().trim();
if (userName.isEmpty()) {
//set error message
return false;
} else if (Password.isEmpty()) {
//set error message
return false;
} else if (Password.length()<6 || Password.length()>15) {
// set error message
return false;
}
return true;
}
添加回答
舉報