This would return true if the second(you're pre-incrementing the loop index) character was a digit, even if the rest of the String contained non-digits.
If you're allowing longer (than 2 char) Strings it'd be better to do:
public boolean simple_validate(String theStr){
char strmyStr = theStr.tocharArray();
for(int i=0; i < strmyStr.length; i++){
if(!Character.isDigit[i]){ // if character is NOT a digit, return false
return false;
}
}
return true; // if we get here, all the characters are digits
}
For very long Strings you might also want to look at using String.charAt(x), and save on the overhead of creating a character array:
public boolean simple_validate(String theStr){
for(int i=0; i < theStr.length(); i++){
if(!theStr.charAt(i).isDigit()) return false;
}
return true;
}
--
Don't Stand on your head - you'll get footprints in your hair
http://charlieharvey.org.uk
http://charlieharvey.com