Percent Repeat

Just quick here, does anyone know a good regex for a percentage? Including 2 decimal places, i.e. 15.22%. I want to put it inside the regularexpressionvalidator in ASP.NET.

0
source share
4 answers

This takes 0.00% -100.00%, including any number of leading zeros:

^0*(100\.00|[0-9]?[0-9]\.[0-9]{2})%$
+4
source
(\d+(\.\d+)?%)

That should work.

+3
source

, @Lucero:

2

^[0-9]+\.[0-9]{2}%$

2 ( ), . .

^[0-9]+(\.[0-9]{2})?%$
0
\d\d\.\d\d%

:

\d\d(\.\d\d)?%

:

\d{1,2}(\.\d\d)?%

, 100%

(100|\d{1,2}(\.\d\d)?)%
0

Source: https://habr.com/ru/post/1770937/


All Articles