0

I want the EURO format to be accepted only in the following forms.

Three digits with "." Be segregated.

i found this expression but not work in my way:

^(0|(([1-9]{1}|[1-9]{1}[0-9]{1}|[1-9]{1}[0-9]{2}){1}(\ [0-9]{3}){0,})),(([0-9]{2})|\-\-)([\ ]{1})(€|EUR|EURO){1}$

I want it to be exactly like the following:

1.123,45

1,23

1.234.567,45

0,56

I want two digit cent to be mandatory.

thanks

4

2 回答 2

2

你可以试试

^(?!0\d)\d{1,3}(?:\.\d{3})*,\d{2}$
  • ^字符串的开头
  • (?!0\d)负前瞻,确保没有前导0s like 01,25,如果允许,将其删除
  • \d{1,3}1 到 3 位数字
  • (?:\.\d{3})*其次是任何出现的文本,如.123
  • ,\d{2}后跟 2 位小数,必填。如果您希望它是可选的,请将其替换为(?:,\d{2})?
  • $字符串的结尾

查看测试用例

于 2021-02-26T07:49:53.723 回答
1
-?(\d{1,3})(\.\d{3})*(,\d{2})? (€|EURO?)

这将捕获数字。您永远不需要{1},因为这是默认假设。空格也不需要转义。

于 2021-02-26T07:47:03.560 回答