Click here to Skip to main content
11,721,289 members (86,406 online)
Click here to Skip to main content

Tagged as

ASP.Net: Clientside Date, Double, Integer,Currency Validation

, 16 Sep 2010 CPOL 22.4K 2
Rate this:
Please Sign up or sign in to vote.
When using text field date, Double type (decimal places or different decimal characters in globalization etc) and currency validation on client-side we often use regular expression validator and try to write complex regular expressions. The easiest way to validate these data types is to use compare

When using text field date, Double type (decimal places or different decimal characters in globalization etc) and currency validation on client-side we often use regular expression validator and try to write complex regular expressions. The easiest way to validate these data types is to use compare validator. I think it’s the most powerful and awesome control for validating data types. All you have to do is to set

Operator=”DataTypeCheck”

And

Type=”<<your required type here >>>”

It supports following types:

  • Date
  • Currency
  • Double
  • Integer
  • String

Look at the following examples:

  • This validates the date according to current culture of the application.
    <asp:TextBox ID=”txtDateStart” CssClass=”input” runat="”server”" Width=”200″>
    </asp:TextBox>
    
    <asp:CompareValidator ID=”cmprValidatorDateStart” ControlToValidate=”txtDateStart” 
        Type=”Date” Display=”Dynamic” Operator=”DataTypeCheck” 
        ErrorMessage=”*Not a valid date.” runat=”server”<>/asp:CompareValidator>
  • This validates double type. The plus point of using this is that for example you set the current culture to German (which uses “,” as a decimal character) it also validates that correctly with no change.
    <asp:TextBox ID=”txtDoubleType” CssClass=”input” runat="”server”" Width=”200″>
    </asp:TextBox>
    
    <asp:CompareValidator ID=”cmprValidatorDoubleType ” ControlToValidate=”
        txtDoubleType” Type=”Double” Display=”Dynamic” Operator=”DataTypeCheck”
        ErrorMessage=”*Not a valid number.” runat=”server”<>/asp:CompareValidator>
  • This validates Currency
    <asp:TextBox ID=”txtCurrencyType” CssClass=”input” runat="”server”" Width=”200″>
    </asp:TextBox>
    
    <asp:CompareValidator ID=”cmprValidatorDoubleType ” ControlToValidate=”
        txtCurrencyType” Type=”Currency” Display=”Dynamic” Operator=”DataTypeCheck”
        ErrorMessage=”*Not a valid amount.” runat=”server”<>/asp:CompareValidator>

Enjoy coding….!

License

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

Share

About the Author

Syed Mujtaba Hassan
Software Developer
Pakistan Pakistan
Syed Mujtaba Hassan
Software Engineer
Intelligentsia Software (Pvt) Ltd Islamabad Pakistan.

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 3 Pin
Gaurang Naik17-Jun-12 23:00
memberGaurang Naik17-Jun-12 23:00 
QuestionGood one Pin
Gaurang Naik17-Jun-12 22:59
memberGaurang Naik17-Jun-12 22:59 
GeneralMy vote of 4 Pin
jesuspinedaq@gmail.com19-Jul-11 11:43
memberjesuspinedaq@gmail.com19-Jul-11 11:43 
GeneralMy vote of 5 Pin
j03x218-Sep-10 4:35
memberj03x218-Sep-10 4:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150901.1 | Last Updated 16 Sep 2010
Article Copyright 2010 by Syed Mujtaba Hassan
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid