locked
Regular Expression RRS feed

  • Question

  • User-1499457942 posted

    Hi

      I have below code for Regular Expression . I have 2 Textbox . Percent & Target . I entered 6.00 & 10.00 . It is giving Invalid Values. I want value should be from 0 to 100. Decimal places can be Optional

    public static bool IsDecimalRange(string input)
    {
    return Regex.IsMatch(input, @"^[1-9][0-9]?$|^100$");
    }

    Thanks

    Sunday, September 16, 2018 11:26 AM

Answers

  • User-893317190 posted

    Hi JagjitSingh,

    You could try this expression.

     public static  bool IsDecimalRange(string input)
            {
                 return Regex.IsMatch(input, @"^[1-9]\d{0,2}(\.\d+)?$|^0(\.\d+)?$");
            }

    \d   is  short for [0-9] , \.  represents  "."  .

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 17, 2018 3:04 AM