Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8994003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:19:25+00:00 2026-06-15T23:19:25+00:00

I have a custom web config class. I want to add RegexStringValidator as an

  • 0

I have a custom web config class. I want to add RegexStringValidator as an attribute to a web config property like:

[ConfigurationProperty("siteDomainName", DefaultValue = "")]
        [RegexStringValidator(@"^([a-zA-Z0-9_-]*(?:\.[a-zA-Z0-9_-]*)+):?([0-9]+)?/?")]
        public string SiteDomainName
        {
            get
            {
                return (string) this["siteDomainName"];
            }
            set 
            { 
                this["siteDomainName"] = value;
            }
        }

The error i am getting is :

The value does not conform to the validation regex string
‘^([a-zA-Z0-9_-]*(?:.[a-zA-Z0-9_-]*)+):?([0-9]+)?/?’.

Even if the value supplied is correct and matches the Regex.
What is the problem with this??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:19:27+00:00Added an answer on June 15, 2026 at 11:19 pm

    Like ronen said in his comment, your default value should also match the regular expression. See this answer for example: https://stackoverflow.com/a/5313223/4830. The reason is that the default value is also evaluated and validated, even when you set a value in your web.config file.

    Something like this should work (default value validates, and property is required so it should never actually use the default value in practice):

    [ConfigurationProperty("siteDomainName", DefaultValue="www.example.com", IsRequired=True)]
    [RegexStringValidator(@"^([a-zA-Z0-9_-]*(?:\.[a-zA-Z0-9_-]*)+):?([0-9]+)?/?")]
    public string SiteDomainName
    ...
    

    In case you don’t want a default value, you could change the regular expression to accept the empty string, by making the whole value basically optional:

    [ConfigurationProperty("siteDomainName", IsRequired=False)]
    [RegexStringValidator(@"^(([a-zA-Z0-9_-]*(?:\.[a-zA-Z0-9_-]*)+):?([0-9]+)?/?)?$")]
    public string SiteDomainName
    ...
    

    Notice that the use of IsRequired in both code examples, use the one that best fits your needs. Be aware that de default value is always going to be validated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a custom section in my web.config like so: <MyMainSection attributeForMainSection
I have registered a custom MembershipProvider class in my Web.Config file. I'm using Inversion
I want to set System.Web.Security.Membership.HashAlgorithmType (or thru web.config) to a custom Cryptography class I
In my web.config, I have a custom Url rewriter class that takes query strings
I have a custom configuration setup. public class GalleryResizeOptionsElement : ConfigurationElement { [ConfigurationProperty(name)] public
I have a web.config of a functioning MOSS server with our custom settings and
I have the following setup: Web.config has customErrors mode=Off Global.Application_Error() event calls a custom
We have a lot of web applications, configured using custom sections (in their web.config
I have an ASP.NET project which has already some custom fields in it's web.config
I have custom configuration section within web.config file. I'm lingering between: Reading it into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.