We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Displaying Success Message for validation control in ASP.NET

souvik2008
souvik2008 asked
on
Medium Priority
409 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.
Comment
Watch Question

Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
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

Author

Commented:
Can you give me the full code of this . That will help me understand what are this objects are all about.
Thanks.
Project manager
CERTIFIED EXPERT
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thank you for your reply.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.