I want the following if statement to compare against multiple strings but when i compare against more than one it gives me the error message that I created. Below is the code which does not work.
The variables are test = 'c3400553' and test2 = 'c3400554'
if (!uname.getText().toString().matches("[cC][0-9]{7}") ||
!uname.getText().toString().equals(test) ||
!uname.getText().toString().equals(test2)
) {
uname.setError("Incorrect ID Format");
}
Below is the code which works for one comparison.
String test = "c3400553";
...
if (!uname.getText().toString().matches("[cC][0-9]{7}") ||
!uname.getText().toString().equals(test)
) {
uname.setError("Incorrect ID Format" );
}
I don't understand what the issue is
&&and||where needed. Also check the usage of!(not operator). Above all, provide a minimal reproducible example