|
|
|
@ -185,4 +185,48 @@ public class StringUtils {
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* <p>Checks if the CharSequence contains only Unicode digits. |
|
|
|
|
* A decimal point is not a Unicode digit and returns false.</p> |
|
|
|
|
* |
|
|
|
|
* <p>{@code null} will return {@code false}. |
|
|
|
|
* An empty CharSequence (length()=0) will return {@code false}.</p> |
|
|
|
|
* |
|
|
|
|
* <p>Note that the method does not allow for a leading sign, either positive or negative. |
|
|
|
|
* Also, if a String passes the numeric test, it may still generate a NumberFormatException |
|
|
|
|
* when parsed by Integer.parseInt or Long.parseLong, e.g. if the value is outside the range |
|
|
|
|
* for int or long respectively.</p> |
|
|
|
|
* |
|
|
|
|
* <pre> |
|
|
|
|
* StringUtils.isNumeric(null) = false |
|
|
|
|
* StringUtils.isNumeric("") = false |
|
|
|
|
* StringUtils.isNumeric(" ") = false |
|
|
|
|
* StringUtils.isNumeric("123") = true |
|
|
|
|
* StringUtils.isNumeric("\u0967\u0968\u0969") = true |
|
|
|
|
* StringUtils.isNumeric("12 3") = false |
|
|
|
|
* StringUtils.isNumeric("ab2c") = false |
|
|
|
|
* StringUtils.isNumeric("12-3") = false |
|
|
|
|
* StringUtils.isNumeric("12.3") = false |
|
|
|
|
* StringUtils.isNumeric("-123") = false |
|
|
|
|
* StringUtils.isNumeric("+123") = false |
|
|
|
|
* </pre> |
|
|
|
|
* |
|
|
|
|
* @param cs the CharSequence to check, may be null |
|
|
|
|
* @return {@code true} if only contains digits, and is non-null |
|
|
|
|
* @since 3.0 Changed signature from isNumeric(String) to isNumeric(CharSequence) |
|
|
|
|
* @since 3.0 Changed "" to return false and not true |
|
|
|
|
*/ |
|
|
|
|
public static boolean isNumeric(final CharSequence cs) { |
|
|
|
|
if (isEmpty(cs)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
final int sz = cs.length(); |
|
|
|
|
for (int i = 0; i < sz; i++) { |
|
|
|
|
if (!Character.isDigit(cs.charAt(i))) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|