• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

Displaying Success Message for validation control in ASP.NET

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
souvik2008
Asked:
souvik2008
  • 2
  • 2
1 Solution
 
DhaestCommented:
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
 
souvik2008Author Commented:
Can you give me the full code of this . That will help me understand what are this objects are all about.
Thanks.
0
 
DhaestCommented:
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
 
souvik2008Author Commented:
Thank you for your reply.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now