Created
September 28, 2017 13:51
-
-
Save benhaxe/544fda12d904c0a228631ce972730543 to your computer and use it in GitHub Desktop.
Real authentication for for edit text filed android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean isFieldValid() { | |
// method to check if all fields are filled well in the registration activity | |
String name = mUsersName.getText().toString().trim(); | |
String email = mUsersMail.getText().toString().trim(); | |
String mobile = mUsersPhone.getText().toString().trim(); | |
String password = mUserPass.getText().toString().trim(); | |
String confirmPass = mConfirmPass.getText().toString().trim(); | |
String address = mAddress.getText().toString().trim(); | |
if (name.isEmpty() || name.length() < 3) { | |
mUsersName.setError("At least 3 characters"); | |
whenRegisterFails("Name should be at least 3 characters"); | |
return false; | |
} else { | |
mUsersName.setError(null); | |
} | |
if (email.isEmpty() || !Patterns.EMAIL_ADDRESS.matcher(email).matches()) { | |
mUsersMail.setError("Enter a valid email address"); | |
whenRegisterFails("Enter a valid email address"); | |
return false; | |
} else { | |
mUsersMail.setError(null); | |
} | |
if (mobile.isEmpty() || mobile.length() < 11 || mobile.length() > 14) { | |
mUsersPhone.setError("Enter Valid Mobile Number"); | |
whenRegisterFails("Enter Valid Mobile Number"); | |
return false; | |
} else { | |
mUsersPhone.setError(null); | |
} | |
if (password.isEmpty() || password.length() < 4 || password.length() > 10) { | |
mUserPass.setError("Between 4 and 10 alphanumeric characters"); | |
whenRegisterFails("Password must be between 4 and 10 alphanumeric characters"); | |
return false; | |
} else { | |
mUserPass.setError(null); | |
} | |
if (confirmPass.isEmpty() || confirmPass.length() < 4 || confirmPass.length() > 10 || !(confirmPass.equals(password))) { | |
mConfirmPass.setError("Passwords do not match"); | |
whenRegisterFails("Passwords do not match"); | |
return false; | |
} else { | |
mConfirmPass.setError(null); | |
} | |
if (address.isEmpty()) { | |
mUsersName.setError("Field Required"); | |
whenRegisterFails("Address can't be emrty"); | |
return false; | |
} else { | |
mUsersName.setError(null); | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool authentication for android developer