是否有替代 StringUtils.isNumeric 的方法可以满足我的意思? [英] Is there an alternative to StringUtils.isNumeric that does what I mean?

查看:27
本文介绍了是否有替代 StringUtils.isNumeric 的方法可以满足我的意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

StringUtils.isNumeric 为 "" 返回 true,为 7.8 返回 false.这当然是记录在案的行为,但对我来说真的不是最方便的.还有其他东西(最好在 commons.lang 中)提供 isActuallyNumeric 吗?

StringUtils.isNumeric returns true for "" and false for 7.8. This is of course it's documented behavior, but really not the most convenient for me. Is there something else (ideally in commons.lang) that provides an isActuallyNumeric?

推荐答案

尝试 isNumber(String) 来自 org.apache.commons.lang.math.NumberUtils.

检查字符串是否 [is] 一个有效的 Java 数字.

Checks whether the String [is] a valid Java number.

有效数字包括用 0x 限定符标记的十六进制,用类型限定符标记的科学记数法和数字(例如123L).

Valid numbers include hexadecimal marked with the 0x qualifier, scientific notation and numbers marked with a type qualifier (e.g. 123L).

Null 和空字符串将返回 false.

Null and empty String will return false.

更新 -

isNumber(String) 现在已弃用.使用 isCreatable(String) 代替.

isNumber(String) is now deprecated. Use isCreatable(String) instead.

感谢eav 指出.

这篇关于是否有替代 StringUtils.isNumeric 的方法可以满足我的意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆