I'm trying to create a function that's returns a boolean true when a find least one illegal character.
I test the following function in JAVA 8 and runs ok but in android return false even with an illegal character inside the string.
First I try this but fail on both environments.
boolean HaveIllegalChars(String cmd)
{
String IllegalChars = "[^*;<>]";
boolean result = cmd.matches(IllegalChars);
return result;
}
Then I read this post Regex doesn't work in String.matches() and change the regex expression and start to works on JAVA; so I paste the same string in Android app but when I run the app in a real device didn't work as expected.
boolean HaveIllegalChars(String cmd)
{
String IllegalChars = ".*[^*;<>].*";
boolean result = cmd.matches(IllegalChars);
return result;
}
Any idea what's happening?
Edit:
I tried the following strings
String illegalStr= "*mmm";
String illegalStr1= "<mmm";
String illegalStr2= ";mmm";
String okStr ="!ABC1";
In JAVA illegalStr returns true(which is what i want) in Android false.
In JAVA illegalStr1 returns true(which is what i want) in Android false.
In JAVA illegalStr2 returns true(which is what i want) in Android false.
In JAVA okStr returns false(which is what i want) in Android false.