Regex for cryptocurrencies(加密货币的正则表达式)

I want to validate some fraction of cryptocurrencies, for example, I have the following VALID values

0,000001
0,000000001
1,00
1.000,00

Right now I have this regex for validating currency (yes, with comma instead of dot)

/^[1-9]\d{0,2}(\.\d{3})*,\d{2}$/

How can I do the same for the values above?

Solution:

You might either match the more exact pattern starting with a digit 1-9, or match a pattern starting with a zero and have 1 or more digits after the comma:

^(?:[1-9]\d{0,2}(?:\.\d{3})*,\d{2}|0\d*,\d+)$

Regex demo

————————

我想验证部分加密货币,例如,我有以下有效值

0,000001
0,000000001
1,00
1.000,00

现在我有一个用于验证货币的正则表达式(是的,用逗号代替点)

/^[1-9]\d{0,2}(\.\d{3})*,\d{2}$/

如何对上述值执行相同的操作?

解决方法:

您可以匹配以数字1-9开头的更精确的模式,或者匹配以零开头且逗号后有1个或多个数字的模式:

^(?:[1-9]\d{0,2}(?:\.\d{3})*,\d{2}|0\d*,\d+)$

正则表达式演示