Click here to Skip to main content
Rate this: bad
good
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 23: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 at 12-Apr-11 4:51am
   
Hey! Jim, I Have already tried this, but no results yet...
jim lahey at 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 at 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
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 12 Apr 2011
Copyright © CodeProject, 1999-2014
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