开发者

RegEx Pattern that matches positive or negative values (e.g "1.2", "-2.8", "7.8", -22.8")

decimal sepera开发者_运维问答tor is a dot, followed by max one digit! No range specified.

Thanks guys!


^-?\d+(\.\d)?$

if the decimal part is optional, and

^-?\d+\.\d$

if it's required :)


Simple: -?\d+\.\d


Unlikely to be relevant in this case, but don't forget that "." is not universal as the decimal separator. Many European countries use "," so you might prefer to get the one in use from the locale:

DecimalFormat df = (DecimalFormat) NumberFormat.getInstance();
String separator = df.getDecimalFormatSymbols().getDecimalSeparator();

(See also: http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormatSymbols.html#getDecimalSeparator)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜