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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:35:44+00:00 2026-06-04T00:35:44+00:00

I have this in an ascx file: <asp:textbox ID=AddHourlyRate runat=server width=55px /> <asp:RegularExpressionValidator ID=AddHourlyRateRegexValidator

  • 0

I have this in an ascx file:

<asp:textbox ID="AddHourlyRate" runat="server" width="55px" />
<asp:RegularExpressionValidator  ID="AddHourlyRateRegexValidator"
    ErrorMessage="Please enter a valid charge rate (whole number only)" 
    ValidationExpression="^\$?[0-9]+(\.[0]{2})?$" ControlToValidate="AddHourlyRate" 
    Display="Dynamic" runat="server" />

How can I reuse the ValidationExpression in other asp:RegularExpressionValidators without having to copy-paste the regex expression? I am new to asp.NET.

  • 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-04T00:35:45+00:00Added an answer on June 4, 2026 at 12:35 am

    Make a class with const string for each regular expression, I use that solution for your exact problem. That class is in a common assembly that is shared among number of projects. And you probably use regular expression on some other places not just validator controls.

    Something like this :

    public class RegularExpressions
    {
      public const string TelephoneValidation = @"^[0-9 ]+$";
      public const string IntegerValidation = @"^\d+$";
    }
    

    You can then set validator expression from code behind :

    validator.ValidationExpression = RegularExpressions.IntegerValidation;
    

    or in markup :

    <%@ Import Namespace="RegularExpression.Class.Namespace" %>  
    .
    .
    .  
    <asp:RegularExpressionValidator  ID="AddHourlyRateRegexValidator"
            ErrorMessage="Please enter a valid charge rate (whole number only)" 
            ValidationExpression="<%# RegularExpressions.IntegerValidation %>" ControlToValidate="AddHourlyRate" 
            Display="Dynamic" runat="server" />
    

    Of course write proper namespace in import directive.

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

Sidebar

Related Questions

For example, i have this ImageViewer.ascx UserControl: <div class=ImageTumbnails> <asp:ListView ID=ImageList runat=server ItemPlaceholderID=ItemContainer> <LayoutTemplate>
I have an ASPX file with this button: <asp:button id=cmdPartnerInfo runat=server Font-Bold=True Text=Partner Info
I have an ASP.NET user control (.ascx file). In this user control I want
When I have the following in my ascx web control: <asp:Literal runat=server Text=<%$Resources:core,Description%> />
Say I have this url: http://site.example/dir/ In this folder I have these files: test.ascx.cs
I have an ascx that uses Eval in a repeater like this: <%@ Control
my structure is like this: master page aspx(web form) ascx(user control) I have a
I have an ImageMap control in an ascx file of mine. I'm trying to
I am working on ASP.NET MVC3. I have a partial view RestaurantAdminNavigation.ascx which i
I have a UserControl which rather than putting tags into its ascx markup file,

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.