Regular Expression for Percentage of marks

前端 未结 4 1848
一向
一向 2021-01-17 17:04

I am trying to create a regex that matches percentage for marks

For example if we consider few percentages

1)100%
2)56.78%
3)56 78.90%
4)34.6789%
         


        
4条回答
  •  自闭症患者
    2021-01-17 17:56

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

    Check this regular expression here: https://regex101.com/r/Ou3mJI/2

    You can use this regular expression. It is valid for:

    1. 0 to 100 inclusive
    2. With and without decimal places

    Below are valid values:

    100% is valid
    99.802% is valid
    98.7% is valid
    57% is valid
    0% is valid

    This regular expression invalidates below values:

    1. Negative numbers
    2. Number > 100
    3. Number with spaces

    Invalid value examples:

    -1%
    99.989%
    101%
    56 78.90%

    Hope this will help!

提交回复
热议问题