I am receiving the value as true when log.d ing the logcat, but when I assign the value to boolean variable it changes to false and also I am not able to do the if condition with the value as it also is showing false. That is I am only able to get the value as true in log, don't know how to take the value to a variable or check some conditions. This code is used to validate a phone number:
Log.d("testi3", "id " + edit_number.getText());
if (number.isEmpty()) {
Log.d("testi3", "id empty" + edit_number.getText());
edit_number.setError(getResources().getString(R.string.phone_error));
isPhoneValid = false;
} else {
Log.d("testi3", "id else " + edit_number.getText());
Pattern ptrn = Pattern.compile("[7-9][0-9]{9}");
Matcher match = ptrn.matcher(number);
Log.d("testi3", "id else 1 " + (match.find() && match.group().equals(number)));
isPhoneValid = (match.find() && match.group().equals(number));
Log.d("testi3", "id else validi" + isPhoneValid);
if ((match.find() && match.group().equals(number))) {
Log.d("testi3", "id else 2 " + (match.find() && match.group().equals(number)));
isPhoneValid = true;
} else {
Log.d("testi3", "id else 3 " + (match.find() && match.group().equals(number)));
edit_number.setError(getResources().getString(R.string.phone_error));
isPhoneValid = false;
}
}
This is the logcat on entering a number as input:
D/testi3: id 9048857563
D/testi3: id else 9048857563
D/testi3: id else 1 true
D/testi3: id else validi false
D/testi3: id else 3 false