private boolean checkPhoneNumber() { EditText checkingPhoneNumber = (EditText)findViewById(R.id.Number); String phoneNumber = checkingPhoneNumber.getText().toString(); if (phoneNumber.length()<8 || phoneNumber.length()>20) { return false; } else { return true; } } private boolean checkEmail() { EditText checkingEmail = (EditText)findViewById(R.id.Email); String email = checkingEmail.getText().toString(); if (email.matches("@") & email.matches(".")) { Email = true; return true; } else { Email = false; return false; } } private boolean checkName() { EditText checkingName = (EditText)findViewById(R.id.Name); String Name = checkingName.getText().toString(); if (Name.length()<3) { name = false; return false; } else { name = true; return true; } } public void onClick(View v){ TextView Hint = (TextView)findViewById(R.id.Hint); if (checkPhoneNumber() == true || checkName() == true || checkEmail() == true) { Intent giftActivity = new Intent(RegistrationActivity.this, GiftHomeActivity.class); startActivity(giftActivity); .... 

Verification does not work. When entering any values, the next activity will still start.

  • Could you change the question according to the minimum reproducible example - pavel
  • four
    Firstly, in your onClick to launch an activity it is enough to fulfill any condition, and not all at once, as you probably want. Secondly, String.matches checks that the entire string matches the regular order, i.e. The only valid email you have is "@". Third, write if ( выражение ) { return true; } else {return false;} if ( выражение ) { return true; } else {return false;} not necessary, you can just return выражение; , equality test выражение == true also superfluous. - zRrr 5:09
  • This code is found on the last page already 4 times. Maybe it's easier for you to order a program on the freelance exchange? - Vladyslav Matviienko

2 answers 2

Your email validation is completely wrong. It is much more difficult than checking whether the email contains a commercial floor and a full stop. In addition, matches does not check whether a substring is contained in a string. You probably mean contains ?
But how to validate email correctly, in the Android SDK there is a special pattern for this:

 public final static boolean isValidEmail(CharSequence target) { if (TextUtils.isEmpty(target)) { return false; } else { return android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches(); } } 

    Most likely an error here:

    if (email.matches ("@") & email.matches ("."))

    You probably meant this statement: &&

    • What's the difference if these are Boolean variables? - pavel
    • I agree with the previous comment - Kirill Avdeev
    • @ Kirill Avdeev, but you don’t have to write like that anyway. Extra function calls. - pavel
    • @pavel Thanks for the good advice, I will note - Kirill Avdeev
    • @pavel, this is already 4 questions about the same problem. I decided to answer at least something) - YuriySPb