473,795 Members | 3,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to validate date?

VC
I have a textbox where users type in a date. I want to check that the input
is between year 2000 and the current date.
Here is segment of the codes that give me the "Server tags cannot contain
<%...%> construct"

<asp:rangevalid ator id="startDateVa lidator" runat="server" Type="Date"
MinimumValue="1/1/2000"
MaximumValue=<% =DateTime.Now.T oShortDateStrin g()%>
..
..
..
</asp:rangevalida tor >

Could anyone help me with codes/way to check whether a date input is within
a range of value, preferably without using the code behind?
Nov 19 '05 #1
1 3156
You almost have it right. You used the old <%= %> ASP style tags. They don't
work inside of properties. DataBinding tags do: <%# [code] %>.
<asp:rangevalid ator id="startDateVa lidator" runat="server" Type="Date"
MinimumValue="1/1/2000" MaximumValue=<% # DateTime.Now.To ShortDateString ()%>
But with databinding, you are required to call the DataBind() method on the
control or the Page to apply it. That means you are going to use some code
in Page_Load. Since that's required, I recommend assigning the property
directly.
Here's databinding:
startDateValida tor.DataBind();
Here's assigning directly:
startDateValida tor.MaximumValu e = DateTime.Now.To ShortDateString ()

The second case is much faster.

Because so many users miss this issue when validating ranges, I wanted to
point it out to you. The RangeValidator will not report an error until the
text is a valid date format because it cannot compare an illegal date to the
range. You should always have a validator for the format of the field. In
this case, its Comparevalidato r with Operator=DataTy peCheck and Type=Date.

--- Peter Blum
www.PeterBlum.c om
Email: PL****@PeterBlu m.com
Creator of "Profession al Validation And More" at
http://www.peterblum.c om/vam/home.aspx

"VC" <vu***@mailbloc ks.com> wrote in message
news:e2******** ******@TK2MSFTN GP14.phx.gbl...
I have a textbox where users type in a date. I want to check that the input
is between year 2000 and the current date.
Here is segment of the codes that give me the "Server tags cannot contain
<%...%> construct"

<asp:rangevalid ator id="startDateVa lidator" runat="server" Type="Date"
MinimumValue="1/1/2000"
MaximumValue=<% =DateTime.Now.T oShortDateStrin g()%>
.
.
.
</asp:rangevalida tor >

Could anyone help me with codes/way to check whether a date input is
within a range of value, preferably without using the code behind?

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2833
by: Alexandre | last post by:
Hi again, What's the best I can do to validate fields like date before send my datas. thx
5
1984
by: Andrew | last post by:
Hi, How can I validate a date, like 3/26/04, before submitted? Thanks for any idea. -- Andrew
2
1888
by: Meredith | last post by:
I am using a script to validate a form using the presence of a value in one field and determine if there is a value in one of two fields. It is an either/or situation. If the date rcvd field is not "", then either the ref names has to be filled in OR the res date has to be filled in. I have tried many combinations of this. Any suggestions will be greatly appreciated. <script language="JavaScript"> function ValidateForm(){
4
1918
by: Frank Rocco | last post by:
Hello, What is the best way to validate a textbox to see if it contains a valid date or a valid time or both? Thanks Frank
6
1975
by: RSB | last post by:
Hi Every one Need some help to Validate the Date i have in the Form. ALso how to Convert the Date Data i read from table to yyyy/MMM/dd format. Thanks RSB
7
31845
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the current date. If not, I'd like to display the error message to ValidationSummary. It seems to make sense to me to use CompareValidator but the problem is put the current date into CompareValidator. So, I created a hidden text field in my aspx. ...
4
4877
by: Michel Posseth [MCP] | last post by:
I have a problem with the date time picker validate event wich i believe is a bug How to reproduce : throw on a form a date time picker control and a textbox control select the validating event of the control and add this code
3
7234
by: samuelberthelot | last post by:
Hello, I would like to validate a date in a textbox on the onChange event. The date must be in the format 01/01/2007 I would like to use a regular expression to validate it but I'm not very familiar with them. How can I do it ? Thanks
2
1945
by: Mick Walker | last post by:
Hi, I have a problem that I have been trying to figure for a couple of days, and am wondering if anyone out there would be so kind as to give me a solution. (Deadline time) I am trying to validate a form. Its quite a simple form, but I am a wee bit stuck. Baically it consists of 9 text input fields and a select element. All elements on the form, have to have a value in them (manditory), BUT 2 items (txtEmail, and txtDOB) have to match...
5
13849
by: shapper | last post by:
Hello, What is the Regex expression to validate a date time format as follows: dd-mm-yyyy hh:mm:ss An example: 20-10-2008 10:32:45
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10435
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9037
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.