2011-05-13 51 views
2

谁能告诉我如何检查在文本框中输入量(印度货币)是否有效或不使用正则表达式印度货币验证表达?定期对使用JavaScript

我有几个条件..

  1. 量不应含有超过1个个小数,但可以有一个小数点。
  2. 如果有小数点,那么它后面应该跟一个或多个数字。
  3. 金额应该只有数字,最多一位小数。
  4. 如果我输入的数量是10.000,那么它不应该被接受,因为它在小数点后有3个连续的零。但应该接受56.8906。
  5. 如果量为零(即0123)开始它不应该被接受,但0.0应该接受
+2

为什么'56.8906'当'10.000'是不是有效? – JohnP 2011-05-13 05:28:05

+0

如果56.8906是美元,你怎么能给56美元和'89.06美分? – 2011-05-13 05:43:46

+0

并非所有的世界都在使用美元。这是卢比。具有3个连续零的 – mplungjan 2011-05-13 05:45:00

回答

3
^(?: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+)?$/; 
+0

谢谢你蒂姆...它的工作正常...非常感谢您的回复.. – Raghu 2011-05-13 06:49:09