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 7822367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:54:33+00:00 2026-06-02T07:54:33+00:00

I have an XML property that has two possible value: discardOld and discardNew (not

  • 0

I have an XML property that has two possible value: discardOld and discardNew (not case sensitive).

I’m trying to come up with a RegEx to validate the input for that particular property:

I tried this one: (?i)(discardnew|discardold) but it doesn’t seem to work.

Any help would be greatly appreciated! Thanks!

UPDATE

This is the code I use to perform the RegEx check:

[ConfigurationProperty("mode", IsRequired = true)]
[RegexStringValidator("(?i)(discardnew|discardold)")]
public string Mode
{
    get { return (string)base["mode"]; }
    set { base["mode"] = value; }
}

This is how the property is declared in XML:

<eventQueue mode="discardNew" />
  • 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-02T07:54:34+00:00Added an answer on June 2, 2026 at 7:54 am

    I tried this and it seems to work correctly (all following IsMatch returns true):

    Regex R = new Regex("(?i)(discardnew|discardold)");
    bool i1 = R.IsMatch("DiscardOld");
    bool i2 = R.IsMatch("discardOld");
    bool i3 = R.IsMatch("discardOLD");
    bool i4 = R.IsMatch("discardneW");
    bool i5 = R.IsMatch("Discardnew");
    bool i6 = R.IsMatch("dISCARDnew");
    

    Problem is probably somewhere else.

    UPDATE:
    This works forr me:

    [ConfigurationProperty("mode", IsRequired = true, DefaultValue = "discardnew")]
    [RegexStringValidator("^(?i)(discardnew|discardold)$")]
    public string Mode
    {
        get { return (string)base["mode"]; }
        set { base["mode"] = value; }
    }
    

    I just added DefaultValue = “discardnew” to ConfigurationProperty. ASP.NET always checks DefaultValue against RegEx even if you don’t set it. Then it considers it to be empty string, which doesn’t validate against your regular expression and so it throws Exception). Also consider addind ^ and $ to regular pattern, otherwise it will validate not only discardnew, but also discardnew1, 1discardnew, etc…

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

Sidebar

Related Questions

I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have two classes, Test2 and Test3. Test2 has an attribute test3 that is
So ... I have build.xml that loads property file from basedir. Then, as the
I'm trying to generate code from an XSD that has two complexTypes extending a
I have two classes. One is called Employee and the other EmployeeDetails that has
I have two WARS: base-overlay example-app base-overlay has XML config files in src/main/webapp/WEB-INF/spring/*.xml .
I have a JSF ManagedBean which has a property that should be set by
I have a Question class that has public List property that can contain several
I have some very simple XML: <properties> <property> <name>BobFish</name> <explaination>Bob is a fish.</explaination> </property>
I have this inside my spring xml file: <object type=Test.Web.Utilities.TestClass, Test.Web singleton=false id=TestClass> <property

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.