Regex for percentage with 2 decimal places javascript

Is there a regex that would validate a percentage value to 2 decimal places?

I have a regex for two decimal places, but don't know how to stop values above 100. e.g. 100.01 is validated with my regex.

DVK

125k31 gold badges208 silver badges321 bronze badges

asked Sep 14, 2009 at 14:51

littlechrislittlechris

4,12410 gold badges42 silver badges66 bronze badges

5

In Perl:

/(^100([.]0{1,2})?)$|(^\d{1,2}([.]\d{1,2})?)$/

or you can just add an extra if comparing 100 exactly :)

Regex for percentage with 2 decimal places javascript

Syscall

18.3k10 gold badges33 silver badges49 bronze badges

answered Sep 14, 2009 at 14:55

7

This allows all percentages except zero.

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

answered Apr 18, 2017 at 12:43

NarayanaNarayana

1051 silver badge8 bronze badges

1

Try this one:

\d{1,2}\.\d{2}

That gives you a one digit or two digit number followed by exactly two decimal places. If you want to allow tenths as well (ala 10.1) then try this:

\d{1,2}\.\d{1,2}

answered Sep 14, 2009 at 14:56

Tony MillerTony Miller

8,9792 gold badges26 silver badges46 bronze badges

2

Try this one (accepts anything between 0 and 100 including 0.00 & 100.00:

^(100\.00|100\.0|100)|([0-9]{1,2}){0,1}(\.[0-9]{1,2}){0,1}$

answered May 13, 2013 at 15:31

Regex for percentage with 2 decimal places javascript

^([0-9]{0,2})(.[0-9]{1,2}){0,1}$|^100$

use this regex for validate the percentage in the angular project or javascript project

Regex for percentage with 2 decimal places javascript

Syscall

18.3k10 gold badges33 silver badges49 bronze badges

answered Mar 12, 2021 at 9:28

Regex for percentage with 2 decimal places javascript

/^(?:100(?:\.0(?:0)?)?|\d{1,2}(?:\.\d{1,2})?)$/

Works with:

  • 100
  • 100.0
  • 100.00
  • 99.99
  • 0.01
  • 5

etc.

Regex for percentage with 2 decimal places javascript

Syscall

18.3k10 gold badges33 silver badges49 bronze badges

answered Sep 14, 2009 at 15:00

XetiusXetius

42.9k24 gold badges83 silver badges119 bronze badges

Keywords

Category

Minimum Rating

Results per Page

Change page:

Regex for percentage with 2 decimal places javascript
Regex for percentage with 2 decimal places javascript
  |    Displaying page 2 of 2 pages; Items 21 to 32

Title Test Details Percent 0.00-100.00
Expression

^100$|^100.00$|^\d{0,2}(\.\d{1,2})? *%?$

Description

Allows percent values from 0 to 100 without the % sign. Can be used with up to 2 decimal places or without any. Also works in ASP.NET regular expression validator control.

Matches

0|0.00|50.25|100|100.00

Non-Matches

100.01|-1|5.005

Title Test Details 0 - 100 Percentage
Expression

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

Description

Match any percentage entered between 0.00 and 100.00%, includes up to 2 decimal places. Percent sign is optional

Matches

100% 100.00 % 95.4% 1.2 % 12

Non-Matches

100.01% 120% -1.2% 95.445% 12%%

Author Rating:
Regex for percentage with 2 decimal places javascript
Tom Grieve
Title Test Details Percentages between -100 and +100 %
Expression

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

Description

Match any percent from -100.00% to +100.00% up to 2 decimla places. Percent sign is optional

Matches

-96.4% -100% 100% 9% 9.10%

Non-Matches

-101% 101% 100.01% 9.288%

Author Rating:
Regex for percentage with 2 decimal places javascript
Tom Grieve
Title Test Details Percentage
Expression

Percentage allowing upto 4 places of decimal

Description

(?!^0*$)(?!^0*\.0*$)^\d{1,2}(\.\d{1,4})?$

Matches

99 12.1 77.25 76.125

Non-Matches

101 100.1 101.25 106.125

Author Rating: Not yet rated. Nilarka Prasanna Das
Title Test Details Vat Rate
Expression

^([1-9]{0,1})([0-9]{1})((\.[0-9]{0,1})([0-9]{1})|(\,[0-9]{0,1})([0-9]{1}))?$

Description

Vat percentage format for Indian and Germany.Maximum two digit before decimal and after decimal

Matches

89.56 | 14.69 | 56,23

Non-Matches

100.56 | 25.365 | 125,56

Author Rating: Not yet rated. Mrinmoy Basu
Title Test Details Percent 1 to 100 (precision 2 decimal places)
Expression

^(100(\.0{0,2}?)?$|([1-9]|[1-9][0-9])(\.\d{1,2})?)$

Description

Only positive values in the range 1.00 to 100.00 (2 decimal places maximum) are valid. The decimal precision is optional. The Percent char % is not used.

Matches

1 100.00 50.05

Non-Matches

0 100.01 50.055

Author Rating: Not yet rated. Kieran Hegarty
Title Test Details 1% to 100% percent
Expression

^([1-9][0-9]?|100)%$

Description

Matches a percentage between 1 and 100. Accepts up to 2 decimal places. No decimal places accepted.

Matches

1% | 52% | 100%

Non-Matches

0% | 100 | 101% | 52 | 52.4%

Author Rating: Not yet rated. Robin Fernando Perdomo
Title Test Details percent validator
Expression

^(-|\+)?(((100|((0|[1-9]{1,2})(\.[0-9]+)?)))|(\.[0-9]+))%?$

Description

validate percentage value passed as a string. Uses posix syntax only so it can be safely used in oracle 10g+ REGEX_SUBSTR and the likes...

Matches

+0.13 -23.04 13% .15% -.002% 00.000

Non-Matches

100.14 130% -102.15%

Author Rating: Not yet rated. nassik
Title Test Details Positive percentage
Expression

^[+]?100(\.0{1,2})?%?$|^[+]?\d{1,2}(\.\d{1,2})?%?$

Description

Matches positive percentage strings with '+' as an optional prefix and '%' as an optional postfix.

Matches

0 00 02 025 2.5 2.50 25.01 100 100.00 +60.63 +70.71% 0.01%

Non-Matches

-1 101 100.01 100 000 +000 25.001 1,50 25%% ++50 70+ 80%+

Author Rating: Not yet rated. Marcel
Title Test Details Percentage
Expression

^100$|^0$|^[1-9]{0,1}[0-9]{0,1}$|^[1-9]{0,1}[0-9]{0,1}\.[0-9]{1,3}$

Description

Or depending on the decimal convention: ^100$|^0$|^[1-9]{0,1}[0-9]{0,1}$|^[1-9]{0,1}[0-9]{0,1}\,[0-9]{1,3}$ Credit to Samir Azza's expression which I used to expand and arrive at the above expression.

Matches

100 | 0 | 99.99 | 10 | 5 | 1.28

Non-Matches

00 | 09.9 | 05.9

Author Rating: Not yet rated. Pedro Sero
Title Test Details https://musclebuildingbuy.com/massive-testo/
Expression

sfsdf

Description

Massive Testo Those with alopecia range from young adults who prefer to shave their heads to middle age men who are wearing hats testosterone to hide their receding hairlines. Well before you decide on using it or any other natural herb to regrow your hair, you need to analyze a few things about it. It's probably 98 to 99 percent male with at least two working girls, who had their own version of over/under. That has eventually come to an end because of social sites like MySpace and Facebook. https://musclebuildingbuy.com/massive-testo/

Matches

ffr

Non-Matches

frrg

Author Rating: Not yet rated. jek gor
Title Test Details RegEx for Percentage in Swift
Expression

^100$|[0-9]{2}\\.[0-9]{2}

Description

This RegEx works for percentage

Matches

100& , 89.23

Non-Matches

101.20 , 99.231

Author Rating:
Regex for percentage with 2 decimal places javascript
vinod kumar

Change page:

Regex for percentage with 2 decimal places javascript
Regex for percentage with 2 decimal places javascript
  |    Displaying page 2 of 2 pages; Items 21 to 32

How do you find a percentage to 2 decimal places?

Suppose your score is 57.114. So, when you want to round it off just write 57.11 as the last digit 4 is less than 5. If your score is 57.118, then as per the rule of rounding of the digits the last digit 8 is greater than 5. So we write the score as 57.12 by increasing 1 to the last digit of the two decimal place.

How do you write a decimal number in regex?

One or more digits ( \d+ ), optional period ( \.? ), zero or more digits ( \d* ).