Click here to Skip to main content
13,861,039 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


6 bookmarked
Posted 27 Sep 2009
Licenced CPOL

CompareValidator’s hidden gem (It does data type validation)

, 28 Sep 2009
Rate this:
Please Sign up or sign in to vote.
After years of working in the .NET environment, you can still find new and amazing features.

Man is small and the .NET environment is vast. After years of working in the .NET environment, you can still find new and amazing features. A user on the ASP.NET forums posted this feature I had never discovered… so I thought I'd pass it along.

The CompareValidator is used to compare the value of data in a textbox, but it can also validate the type of data entered into a textbox.

It can validate these types:

  • String
  • Integer
  • Date
  • Double
  • Currency

You have to set the Operator attribute to DataTypeCheck and the Type attribute to one of the above values.

Here's a link with the details:

Here's an example:

<asp:TextBox ID="TextBoxInteger" runat="server"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" 




    ErrorMessage="Please enter an integer" />

<asp:TextBox ID="TextBoxDate" runat="server"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator2" runat="server" 




    ErrorMessage="Please enter a valid Date" />

I hope someone finds this useful.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Steve Wellens
EndWell Software, Inc.
United States United States
I am an independent contractor/consultant working in the Twin Cities area in Minnesota. I work in .Net, Asp.Net, C#, C++, XML, SQL, Windows Forms, HTML, CSS, etc., etc., etc.

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190214.1 | Last Updated 28 Sep 2009
Article Copyright 2009 by Steve Wellens
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid