Although the number of digits is limited this actually creates a variable of the data which can be used, which is, I would imagine, the most common use-case. Such as you want to actually use the data in your code, not just validate it.
Trying to parse string as a long value is inefficient and unreliable, and may be not what you need. Is it really worth adding a whole library for this feature though?Obviously if it's used with other stuff that's great, but it's probably overkill considering people have solved this in one line of code.However, if you're calling this function a lot, and you expect many of the checks to fail due to not being a number then performance of this mechanism will not be great, since you're relying upon exceptions being thrown for each failure, which is a fairly expensive operation.An alternative approach may be to use a regular expression to check for validity of being a number: Be careful with the above Reg Ex mechanism, though, as it'll fail if you're using non-arabic digits (i.e. This is because the "\d" part of the Reg Ex will only match [0-9] and effectively isn't internationally numerically aware. ) Or even another alternative is to use Java's built-in