使用JavaScript进行印度货币验证的正则表达式 [英] Regular expression for Indian Currency validation using JavaScript
本文介绍了使用JavaScript进行印度货币验证的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我如何使用正则表达式检查文本框中输入的金额(印度货币)是否有效?
Can anyone please tell me how to check whether the entered amount (Indian currency) in a textbox is valid or not using regular expression?
我的条件很少。 。
- 金额不应超过1个小数点,但可以只有一个小数点。
- 如果有小数点,则后面应跟一个或多个数字。
- 金额应该只有数字,最多只能有一个小数点。
- 如果我输入类似10.000的金额,则不应接受它,因为它在小数点后有3个连续的零。但是应该接受56.8906。
- 如果金额从零开始(即0123),则不应接受,但应接受0.0
- The amount should not contain more than 1 decimal point, but can have a single decimal point.
- If there is a decimal point then it should be followed by one or more digits.
- The amount should have only numbers and at most one decimal point.
- If I enter an amount like 10.000 then it should not be accepted because it has 3 continuous zeros after decimal point. but 56.8906 should be accepted.
- If the amount starts with zero (ie 0123) it should not be accepted, but 0.0 should be accepted
推荐答案
^(?: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中:
In JavaScript:
curRegExp = /^(?:0|[1-9]\d*)(?:\.(?!.*000)\d+)?$/;
这篇关于使用JavaScript进行印度货币验证的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文