Displaying Success Message for validation control in ASP.NET

Posted on 2009-02-12
Last Modified: 2013-12-17
I am trying to add a success message for the correct input type in a asp text box which uses the regularexpression validator . But I could not succeed as there is an errormessage property of ASP.NET which works for me for the incorrect input but I could not found any properties or method of validation control which executes the validation of the text field and gives the result back to the user whether it is success or an error. I have tried the regualrexpressionfieldvalidator.IsValid but it also doesn't worked for me.
Question by:souvik2008
    LVL 53

    Expert Comment

    You will need to check this through coding

    textReplaceResults.Text = "N/A";
            if (Regex.IsMatch(textSubject.Text, textRegex.Text, getRegexOptions())) {
              textResults.Text = "The regex matches part or all of the subject";
            } else {
              textResults.Text = "The regex cannot be matched in the subject";
          catch (Exception ex)
            // Most likely cause is a syntax error in the regular expression
            textResults.Text = "Regex.IsMatch() threw an exception:\r\n" + ex.Message;

    Open in new window

    LVL 2

    Author Comment

    Can you give me the full code of this . That will help me understand what are this objects are all about.
    LVL 53

    Accepted Solution

    For more info:
    <%@ Page Language="C#" %>
    <html  >
        <form id="form1" method="post" action="HtmlControls.aspx">
            <input name="txtName" type="text" />
            <input name="submitBtn" type="Submit" value="Submit"/>
    <script runat="server">
      void Page_Load(object sender, EventArgs e)
        if (Request.RequestType == "POST")
          string name = Request.Form["txtName"];
          if (name.Length > 0)
            if (System.Text.RegularExpressions.Regex.IsMatch(name, 
              Response.Write("Valid name");
              Response.Write("Invalid name");

    Open in new window

    LVL 2

    Author Closing Comment

    Thank you for your reply.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now