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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:12:41+00:00 2026-05-23T17:12:41+00:00

I have to use a Regular expression validator for username property in my model.

  • 0

I have to use a Regular expression validator for username property in my model.
I am getting this regular expression from the config file.

[RegularExpression(UsernameValidationExpression)] //UsernameValidationExpression = value from the config file
public string UserName { get; set; }

Here i am getting an error
“An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type”

How can i solve 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-05-23T17:12:42+00:00Added an answer on May 23, 2026 at 5:12 pm
    public class ConfigRegularExpressionAttribute : RegularExpressionAttribute
    {
        public ConfigRegularExpressionAttribute(string patternConfigKey)
            : base(ConfigurationManager.AppSettings[patternConfigKey])
        { }
    }
    

    and then:

    [ConfigRegularExpression("UsernameValidationExpression")]
    public string UserName { get; set; }
    

    and in web.config:

    <appSettings>
        <add key="UsernameValidationExpression" value="foo bar" />
    </appSettings>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use in my model following regular expression for getting a number that must
I am using regular expression. In phone validation, i have to use the +
I would like to use regular expression to check if my string have the
Does anyone have a Regular Expression to validate legal FQDN? Now, I use on
I have a regular expression that I use to reduce multiple slashes to single
I have 20-25 textboxes in the form. should I use regular expression control in
I have a syntax highlighting function in vb.net. I use regular expressions to match
Hi have some forms that I want to use some basic php validation (regular
I am trying to use validatevalue:forkey: method to validate a coredata property. I have
I need to validate serial numbers. For this we use regular expressions in C#,

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.