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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:13:42+00:00 2026-06-09T20:13:42+00:00

Thanks for any thoughts. while I am working my way through some custom validationAttributes,

  • 0

Thanks for any thoughts.

while I am working my way through some custom validationAttributes, I have come across a problem which should be simple, but has me stumped.

An authorized user will have a UserProfile which includes a key to the site they work in. This site is a record set within a database. 1 field in this site record set is a regular expression which denotes what would be a valid format for a field in a completely separate table. The data entered into this other table will be common to all registered users, but a particular field relates to the ID format used at their institution.

Is there a clean way I can dynamically add a regular expression validator to a property?

Thank you as always.

  • 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-09T20:13:44+00:00Added an answer on June 9, 2026 at 8:13 pm

    This is what I came up with, but keen to know if there are better solutions:

    Naming conventions are to allow automapper to flatten the model (each StudyCentre has a many to 1 relationship with the RecordSystem (some systems share the patient indexing system)

    Mapper.CreateMap<StudyCentre, ParticipantRegistration.StudyCentreViewData>();
    

    As a nested class within the ViewModel for an indidual TrialParticipant

    public StudyCentreViewData ViewData { get; set; }
    public class StudyCentreViewData
    {
        public string Abbreviation { get; set; }
        public string RecordSystemName { get; set; }
        public string RecordSystemHospitalNoRegEx { get; set; }
        public string RecordSystemNotationDescription { get; set; }
        public IDictionary<string, object> HospitalNoRegEx()
        {
             return DynamicClientValidation.RegEx(errorMessage:String.Format("{0} must consist of {1}",
                                                                           RecordSystemName,
                                                                           RecordSystemNotationDescription),
                                                  regExPattern: RecordSystemHospitalNoRegEx);
        }
    }
    

    The other properties (such as StudyCentre.Abbreviation are for the labels)
    The function RegEx is simply:

    public static class DynamicClientValidation
    {
        public static IDictionary<string, object> RegEx(string errorMessage, string regExPattern)
        {
            var returnVal = new Dictionary<string, object>(3);
            returnVal.Add("data-val-regex", errorMessage);
            returnVal.Add("data-val-regex-pattern", regExPattern);
            returnVal.Add("data-val", "true");
            return returnVal;
        }
    }
    

    The Controller sets up the viewmodel like so:

    model.ViewData = Mapper.Map<StudyCentre, ParticipantRegistration.StudyCentreViewData>(_studyCentre.GetCentreByUser(_currentUserName));
    

    and in the view (LabelDetailsfor is a custom helper):

    <div class="editor-label">
        @Html.LabelDetailsFor(model => model.HospitalID,Model.ViewData.Abbreviation + " ID", Model.ViewData.RecordSystemName) 
    </div>
    <div class="editor-field">
        @Html.TextBoxFor(model => model.HospitalID, Model.ViewData.HospitalNoRegEx())
        @Html.ValidationMessageFor(model => model.HospitalID)
     </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While researching how to create custom compound views in Android, I have come across
Still learning WPF....thanks for any help. Is there any way to Refactor this: <ListBox
Is there any way to suppress Compiler warnings ?? Thanks
Is there any way to access the iPhone/iPod touch settings programatically ? Thanks. Biranchi
I have been working with Struts for some time, but for a project I
Is there a way to kill a PHP program while it's working? I know
I'm working on a problem in C# 2.0/.NET 2.0 where I have a Sortedlist
Thanks for any help in advance, I can't wrap my SQL skills around this
i've been asked this question and id not know the answer. Thanks for any
As title Welcome any comment Thanks interdev

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.