[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Displaying Success Message for validation control in ASP.NET

Posted on 2009-02-12
4
Medium Priority
?
364 Views
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.
0
Comment
Question by:souvik2008
  • 2
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 23630440
You will need to check this through coding


textReplaceResults.Text = "N/A";
      try
      {
        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

0
 
LVL 2

Author Comment

by:souvik2008
ID: 23640440
Can you give me the full code of this . That will help me understand what are this objects are all about.
Thanks.
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 375 total points
ID: 23647686
For more info: http://msdn.microsoft.com/en-us/library/ms998267.aspx
or http://www.devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=46
<%@ Page Language="C#" %>
 
<html  >
  <body>
    <form id="form1" method="post" action="HtmlControls.aspx">
        Name:
        <input name="txtName" type="text" />
        <input name="submitBtn" type="Submit" value="Submit"/>
    </form>
  </body>
</html>
 
<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, 
                                           "^[a-zA-Z'.]{1,40}$"))
          Response.Write("Valid name");
        else
          Response.Write("Invalid name");
      }
    }
  }
 
</script>

Open in new window

0
 
LVL 2

Author Closing Comment

by:souvik2008
ID: 31546459
Thank you for your reply.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

872 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