Okey...
first :
for name you don't want allow user to enter numbers so what you can do is add two attributes to your name EditText
.
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
android:inputType="text"
This will allow user to enter only alphabets and blank space. so no need for verification on that programmatically.
Second :
Same for the telephone number. you have to add android:inputType="number"
to your telephone EditText
. So user will able to input numbers only.
Third
for validating if your EditText
is empty or not you can do following.
if (name.getText().toString().equals("")) {
Toast.makeText(getApplicationContext(),
"Please enter your name", Toast.LENGTH_SHORT).show();
}
Fourth
For checking password equality you can do following.
if (!password1.getText().toString().equals(password2.getText().toString())) {
Toast.makeText(getApplicationContext(),
"Please enter your name", Toast.LENGTH_SHORT).show();
}
Now Hopefully you understand this whole process. for your case refer following code.
if (name.getText().toString().equals("") || name.length() < 3 ||) {
et_name.setError("enter a valid name");
valid = false;
}
if (tel.getText().toString().equals("")) {
et_tel.setError("enter a valid tel");
valid = false;
}
if (password.getText().toString().equals("") || password2.getText().toString().equals("") || !password.getText().toString().equals(password2.getText().toString())) {
et_password.setError("enter a valid password");
valid = false;
}
Happy coding.