Click here to Skip to main content
12,944,475 members (51,705 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.
Thanks.
Posted 11-Apr-11 22:41pm
Rate this: bad
 
good
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.">
</asp:CompareValidator>





Using user input limit :

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

Good luck!
  Permalink  
Rate this: bad
 
good
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:

^(([0-9])|([0-2][0-9])|([3][0-1]))\/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\/\d{4}$


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

More info for validation controls in ASP.net can be found here:

http://msdn.microsoft.com/en-us/library/debza5t0.aspx[^]
  Permalink  
Comments
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?

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.causesvalidation.aspx
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
 
good
Please Sign up or sign in to vote.

Solution 2

try this LINK
Click[^]
  Permalink  
Rate this: bad
 
good
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"
                                                            TargetControlID="txtGsmNo">
                                                        </cc1:FilteredTextBoxExtender>
  Permalink  
v2

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,651
CHill60 3,055
Maciej Los 2,423
Jochen Arndt 1,910
ppolymorphe 1,765


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