^(?:0|[1-9]\d*)(?:\.(?!.*000)\d+)?$
应该做你想要什么。
说明:
^ # Start of string.
(?: # Try to match...
0 # either a 0
| # or
[1-9]\d* # an integer number > 0, no leading 0 allowed.
) # End of integer part.
(?: # Try to match...
\. # a decimal point.
(?! # Assert that it's not possible to match
.*000 # any string that contains 000 from this point onwards.
) # End of lookahead assertion.
\d+ # Match one or more digits.
)? # End of the (optional) decimal part
$ # End of string.
在JavaScript:
curRegExp = /^(?:0|[1-9]\d*)(?:\.(?!.*000)\d+)?$/;
为什么'56.8906'当'10.000'是不是有效? – JohnP 2011-05-13 05:28:05
如果56.8906是美元,你怎么能给56美元和'89.06美分? – 2011-05-13 05:43:46
并非所有的世界都在使用美元。这是卢比。具有3个连续零的 – mplungjan 2011-05-13 05:45:00