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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:31:05+00:00 2026-06-14T12:31:05+00:00

I want to use the asp:RegularExpressionValidator control to validate a number of text boxes.

  • 0

I want to use the asp:RegularExpressionValidator control to validate a number of text boxes. Some of the textboxes contain email addresses. I don’t want to repeat the same regular expression in the attributes of the RegularExpressionValidator for each different text box. Therefore I define the expression as a constant in my code-behind

Const regEmail As String = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"

Similarly, I define the error message this way.

const regEmailMsg = "Email address does not appear to be valid."

However, I cannot find a way to include these strings in the RegularExpressionValidator controls in my ASPX page that works. Valid expressions are flagged as invalid. As an additional failure, the ValidatorCalloutExtender appears but its middle section is missing – the error message does not appear. Here is an example textbox and validator:

<asp:TextBox ID="txtIndividualEmail" runat="server" Width = "200"></asp:TextBox>

<asp:RegularExpressionValidator ID="revIndividualEmail" runat="server" ErrorMessage="<% =regEmailMsg %>" Display="None" 
ControlToValidate="txtIndividualEmail" ValidationExpression="<% =regEmail %>" >    </asp:RegularExpressionValidator>

<cc1:ValidatorCalloutExtender ID="vceIndividualEmail" runat="server" 
Enabled="True" TargetControlID="revIndividualEmail" HighlightCssClass="validatorCalloutHighlight">
</cc1:ValidatorCalloutExtender>

When I include the strings directly in the ASPX everything works fine:

<asp:RegularExpressionValidator ID="revIndividualEmail" runat="server" ErrorMessage="Email address does not appear to be valid." Display="None" 
ControlToValidate="txtIndividualEmail" ValidationExpression="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"

Email is just one example of where I want to re-use a string for validation, and therefore don’t want to be repeating it in my ASPX. Is there a way to do 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-14T12:31:06+00:00Added an answer on June 14, 2026 at 12:31 pm

    The only thing you can really do here is to set the properties in the code-behind in an OnInit or OnLoad event. Something like:

    protected override void OnLoad(EventArgs e)
    {
       txtIndividualEmail.ValidationExpression = myExpressionConstant;
       txtIndividualEmail.ErrorMessage = myErrorMessageConstant;
       // etc
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to use forms authentication without login control.I don't want to use asp.net login
I want to use an ASP.NET RegularExpressionValidator to limit the number of words in
I have a Panel control that contains some control such as text boxes.I want
I want to use some ASP.NET based CMS for creating my website and don't
I want to use an ASP:RegularExpressionValidator to enforce a minimum character count (6) but
I have an asp.net user control on which I want to use jquery ajax.
If I want to use ASP.Net without the Microsoft AJAX Control Toolkit or JQuery
I have an Asp.Net website and I want to use a RegularExpressionValidator to check
I want to use asp.net repeater control to display all threads that under same
I dont want to use asp.net's TreeView control. I want to create a custom

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.