Is there an alternative to StringUtils.isNumeric that does what I mean?
NumberUtils.isNumber is deprecated.
Your should use
NumberUtils.isCreatable
or
NumberUtils.isParsable
All of them support a decimal point value:
- NumberUtils.isCreatable support hexadecimal, octal numbers, scientific notation and numbers marked with a type qualifier (e.g. 123L). Not valid octal values will return
false
(e.g. 09). If you want get its value, you should use NumberUtils.createNumber. - NumberUtils.isParsable only support
0~9
and decimal point (.
), any other character (e.g. space or other anything) will returnfalse
.
By the way, StringUtils.isNumeric
's implement has some different between commons-lang and commons-lang3. In commons-lang, StringUtils.isNumeric("") is true
. But in commons-lang3, StringUtils.isNumeric("") is false
. You can get more info by documents.
Try isNumber(String)
from org.apache.commons.lang.math.NumberUtils
.
Checks whether the String [is] a valid Java number.
Valid numbers include hexadecimal marked with the 0x qualifier, scientific notation and numbers marked with a type qualifier (e.g. 123L).
Null
and empty String will returnfalse
.
UPDATE -
isNumber(String)
is now deprecated. Use isCreatable(String)
instead.
Thank you eav for pointing it out.