From 40a60c86da55f9ced2eaf6492f8aeb96a1d926b8 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 28 Dec 2018 13:36:08 +0100 Subject: [PATCH] [New] Added new StringHelper.isAllDigits() --- .../li/strolch/utils/helper/StringHelper.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/li.strolch.utils/src/main/java/li/strolch/utils/helper/StringHelper.java b/li.strolch.utils/src/main/java/li/strolch/utils/helper/StringHelper.java index 38cff688c..8ccca61fa 100644 --- a/li.strolch.utils/src/main/java/li/strolch/utils/helper/StringHelper.java +++ b/li.strolch.utils/src/main/java/li/strolch/utils/helper/StringHelper.java @@ -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; + } + /** *

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.