支持多种货币格式的正则表达式 [英] Regular Expression that supports multiple currency formats
本文介绍了支持多种货币格式的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个正则表达式,需要验证文本是否为受支持的货币格式.
I have a regular expression that needs to validate if the text is in a supported currency format.
^(\$|€|Fr.|£|kr|R?)\s*((([1-9](,\d{3}){3})|([1-9]\d{0,2}(,\d{3}){0,2})|(\d{1,10}))(\.\d{1,2})?)\s*(\$|€|Fr.|£|kr|R?)$
我支持以下内容:
-
US Dollar (10000.00 or 10,000.00 or $10,000.00)
-
Euro (10000.00 or 10,000.00 or €10,000.00)
-
Francs (10000.00 or 10'000.00 or Fr.10'000.00)
-
Pounds (10000.00 or 10'000.00 or £10,000.00)
-
Kroner (10000,00 or 10'000.00 or 10.000,00 kr)
-
Rand (10000.00 or 10,000.00 or R10,000.00)
US Dollar (10000.00 or 10,000.00 or $10,000.00)
Euro (10000.00 or 10,000.00 or €10,000.00)
Francs (10000.00 or 10'000.00 or Fr.10'000.00)
Pounds (10000.00 or 10'000.00 or £10,000.00)
Kroner (10000,00 or 10'000.00 or 10.000,00 kr)
Rand (10000.00 or 10,000.00 or R10,000.00)
我对其进行了更新,以支持上述所有格式.
I updated it to support all of the above formats.
^(\$|€|Fr.|£|kr|R?)\s*(((([1-9](,\d{3}){3})|([1-9]\d{0,2}(,\d{3}){0,2})|(\d{1,10}))(\.\d{1,2})?)|((([1-9](.\d{3}){3})|([1-9]\d{0,2}(.\d{3}){0,2})|(\d{1,10}))(\,\d{1,2})?)|((([1-9]('\d{3}){3})|([1-9]\d{0,2}('\d{3}){0,2})|(\d{1,10}))(\.\d{1,2})?))\s*(\$|€|Fr.|£|kr|R?)$
看起来不错,但是我不知道为什么当我使用这些格式时,为什么它也接受小数点后3位.
It looks fine, but I don't know why it also accepts 3 decimal place when I have these formats.
100,000.012
200.000,002
100'000.001
我只能接受2个小数位.
I should only accept 2 decimal places.
推荐答案
我认为您需要删除?在\ d {1,2}中)?
I think you need to remove the ? in \d{1,2})?
这篇关于支持多种货币格式的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文