0

Need to apply Regex validation for a string with semicolon separated HTTP status codes:

"202;500;503"

I tried this regex

^([0-9]+;)*[0-9]+$

but i get an exception:

The value for the property 'retryStatusCodes' is not valid. The error is: The value does not conform to the validation regex string ^([0-9]+;)*[0-9]+$.

How is that possible? I tested it here: https://regexr.com/

and it worked

Why it doesnt work in C# code?

I use it for validation of attrtibutes in ConfigurationSectionDesigner, auto-generated code for this attribute:

    /// <summary>
    /// Gets or sets the RetryStatusCodes.
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ConfigurationSectionDesigner.CsdFileGenerator", "2.0.3.2")]
    [global::System.ComponentModel.DescriptionAttribute("The RetryStatusCodes.")]
    [global::System.Configuration.RegexStringValidatorAttribute("^([0-9]+;)*[0-9]+$")]
    [global::System.Configuration.ConfigurationPropertyAttribute(global::XXX.XXX.XXX.RetryStatusCodesPropertyName, IsRequired=true, IsKey=false, IsDefaultCollection=false)]
    public virtual string RetryStatusCodes
    {
        get
        {
            return ((string)(base[global::XXX.XXX.XXX.RetryStatusCodesPropertyName]));
        }
        set
        {
            base[global::XXX.XXX.XXX.RetryStatusCodesPropertyName] = value;
        }
    }
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
monstro
  • 6,254
  • 10
  • 65
  • 111
  • it is because you validate javascript on https://regexr.com/ – Dyragor May 30 '18 at 13:30
  • Well, it is not a problem to test such a simple regex at regexr.com. It works the same in JS and C#. Please check [this post](https://stackoverflow.com/questions/4149398/unexpected-regexstringvalidator-failure-in-configurationproperty-in-custom-confi) where a similar issue is discussed (also, a simple regex and the same exception). – Wiktor Stribiżew May 30 '18 at 13:35

0 Answers0