Validate Android registration details posting to MyQSL database


I created an if else statement to check for valid inputs within the email, password, and blank spaces for the text box. The functions work correctly when I test the cases , BUT it continues to post to the MYSQL database with incorrect registration information. I don't know why because it should immediately RETURN when it hits the if else block and not continue to execute the JSON code.

How can I prevent it from registering to the DATABASE with wrong information?

btnRegister.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String name = inputFullName.getText().toString();
String email = inputEmail.getText().toString();
String password = inputPassword.getText().toString();
String check = checkpass.getText().toString();
UserFunctions userFunction = new UserFunctions();
JSONObject json = userFunction.registerUser(name, email, password);
boolean ret = false;

if (!inputEmail.getText().toString().matches("[a-zA-Z0-9._-]+@[a-z]+.[a-z]+") && email.length() > 0)
Toast.makeText(getApplicationContext(), "Enter Valid Email Address", Toast.LENGTH_LONG).show();

if(name != null && name.trim().length() ==0 || email != null && email.trim().length() ==0|| password != null && password.trim().length() ==0||check != null && check.trim().length() ==0)
Toast.makeText(getApplicationContext(), "Field Vaccant", Toast.LENGTH_LONG).show();
// check if both password matches
else if(!password.equals(checkpass))
Toast.makeText(getApplicationContext(), "Password does not match", Toast.LENGTH_LONG).show();

// Save the Data in Database
// check for login response
try {

if (json.getString(KEY_SUCCESS) != null) {
String res = json.getString(KEY_SUCCESS);
if(Integer.parseInt(res) == 1){
// user successfully registred
// Store user details in SQLite Database
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
JSONObject json_user = json.getJSONObject("user");

// Clear all previous data in database
db.addUser(json_user.getString(KEY_NAME), json_user.getString(KEY_EMAIL), json.getString(KEY_UID), json_user.getString(KEY_CREATED_AT));
// Launch Dashboard Screen
Intent dashboard = new Intent(getApplicationContext(), DashboardActivity.class);
// Close all views before launching Dashboard
// Close Registration Screen
// Error in registration
registerErrorMsg.setText("User already Registered");
catch (JSONException e) {


// Link to Login Screen
btnLinkToLogin.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {
Intent I = new Intent(getApplicationContext(),
// Close Registration View


Android Enthusiast
I haven't really bothered to do any coding for years, and even then it was some college intro to C++ thing. But.....

It looks like when you clear all the database / function strings for the next entry, KEY_SUCCESS isn't getting cleared. Perhaps that is related?

Nevermind, read that wrong. Not sure why it's doing it.