Click here to Skip to main content
12,945,800 members (53,737 online)
Rate this:
Please Sign up or sign in to vote.
Hi! All,
I have a ASP textbox, and i accept the date in dd-MMM-yyyy format i.e. 01-Jan-2001,
using AJAX Calendar. How can i validate the input of the textbox so that no endusers can enter any characters or any formats.
I just want to restrict users to enter in the specified format in the textbox, if a user enters some other characters he sould be promted to enter in dd-MMM-yyyy.
Posted 11-Apr-11 22:41pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

You can either use an asp validator or limit the user to type on your date textbox.

Using validator:

<asp:CompareValidator id="dateValidator" runat="server"
  Type="Date" Operator="DataTypeCheck" ControlToValidate="dateTextbox"
  ErrorMessage="Please enter a valid date.">

Using user input limit :

Since you're using Ajax calendar, check your TargetControlID property and set it to readonly.

Good luck!
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use a RegularExpressionValidator and set it's ControlToValidateID property to the ID of the TextBox. The ValidationExpression of the RegularExpressionValidator will look something like this:


You might also need a ValidationSummary, depending on your scenario.

More info for validation controls in can be found here:[^]
Nischal Bhatt 12-Apr-11 4:51am
Hey! Jim, I Have already tried this, but no results yet...
jim lahey 12-Apr-11 4:56am
Have you set CausesValidation on the TextBox?
BobJanova 12-Apr-11 5:34am
Remember that the month names might be different for different languages.

If you're doing a server side validation, you might as well just try to parse what they provided as a date. Forcing them to enter it in one format is pointless. Any format validation should be done with JS on the client side – its purpose is to avoid unnecessary postback-reload cycles because you didn't type a date right.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

try this LINK
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

<asp:TextBox ID="txtGsmNo" Width="70px" runat="server"
                                    MaxLength="7" CssClass="select" Height="16px"></asp:TextBox>

<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender4" runat="server" FilterType="Numbers"

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,180
Maciej Los 2,453
Jochen Arndt 1,910
ppolymorphe 1,785

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 12 Apr 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100