如何從EditText上 註冊使用Android Studio用戶之前驗證電子郵件&密碼輸入...如何驗證從EditText上電子郵件和密碼輸入註冊用戶
電子郵件:必須包含@符號和其他一般要求密碼: 必須> 6位數字。
請修改此代碼。 我的代碼是...
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener{
private Button buttonRegister;
private EditText editTextEmail;
private EditText editTextPassword;
private TextView textViewSignin;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
firebaseAuth=FirebaseAuth.getInstance();
if (firebaseAuth.getCurrentUser()!=null){
//profile activity here
finish();
startActivity(new Intent(getApplicationContext(),ProfileActivity.class));
}
progressDialog = new ProgressDialog(this);
buttonRegister = (Button)findViewById(R.id.buttonRegister);
editTextEmail = (EditText)findViewById(R.id.editTextEmail);
editTextPassword = (EditText)findViewById(R.id.editTextPassword);
textViewSignin = (TextView)findViewById(R.id.textViewSignin);
buttonRegister.setOnClickListener(this);
textViewSignin.setOnClickListener(this);
}
private void registerUser(){
final String email = editTextEmail.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
//uset cannot go any further without entering password
if(TextUtils.isEmpty(email)){
//email is empty
Toast.makeText(this, "Please enter email",Toast.LENGTH_SHORT).show();
//stopping execution further
return;
}
if(TextUtils.isEmpty(password)){
//password is empty
Toast.makeText(this, "Please enter password",Toast.LENGTH_SHORT).show();
//stopping execution further
return;
}
//if validations are ok
//we will first show progressbar
progressDialog.setMessage("Registerating User...");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
//user is successfully registered. we will start profile activity here
FirebaseUser user = firebaseAuth.getCurrentUser();
Toast.makeText(RegisterActivity.this, "Authentication success. " + user.getUid(), Toast.LENGTH_SHORT).show();
progressDialog.hide();
finish();
startActivity(new Intent(getApplicationContext(),ProfileActivity.class));
}
else{
Toast.makeText(RegisterActivity.this, "Could not register. please try again", Toast.LENGTH_SHORT).show();
progressDialog.hide();
}
}
});
}
@Override
public void onClick(View v) {
if (v==buttonRegister){
registerUser();
}
if(v==textViewSignin){
finish();
startActivity(new Intent(this, LoginActivity.class));
}
}
}
,添加的inputType屬性的EditText和密碼,編程獲取它,使用 'gettext的()。的toString()',然後檢查長度這個字符串。 –