Slava
Slava

Reputation: 6650

Regex for semicolon separated numbers string in ConfigurationSectionDesigner validation?

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;
        }
    }

Upvotes: 0

Views: 32

Answers (0)

Related Questions