[New] Added new StringHelper.isAllDigits()

This commit is contained in:
Robert von Burg 2018-12-28 13:36:08 +01:00
parent 94b0dd4f5a
commit 40a60c86da
1 changed files with 17 additions and 0 deletions

View File

@ -711,6 +711,23 @@ public class StringHelper {
return value != null && !value.isEmpty();
}
/**
* Checks if all characters in the string are digits
*
* @param value
* the value to check
*
* @return true if all characters are digits, false if not, i.e. a letter, special character or a minus, etc.
*/
public static boolean isAllDigits(String value) {
for (int i = 0; i < value.length(); i++) {
if (!Character.isDigit(value.charAt(i)))
return false;
}
return true;
}
/**
* <p> Parses the given string value to a boolean. This extends the default {@link Boolean#parseBoolean(String)} as
* it throws an exception if the string value is not equal to "true" or "false" being case insensitive. </p>