473,549 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validating 2 date fields

Hi All

I have a <SELECT> for the month (1 .. 12) and a <SELECT> for the year (2004
.... 2020), do you know of any js validation check I can use to check whether
these values are older than today's date so that I can bring up a warning,
eg

user chooses 04 and 2003 or 01 and 2004

OnClick a validate script sees that either of the above are older than
today's date and brings up an alert/doesn't submit the form.

Any ideas?

Rgds

Robbie


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 23 '05 #1
5 2369
Astra wrote:
Hi All

I have a <SELECT> for the month (1 .. 12) and a <SELECT> for the year (2004
... 2020), do you know of any js validation check I can use to check whether
these values are older than today's date so that I can bring up a warning,
eg


Do a search on "Re: Date format dd/mm" and a post by Mike Winter on
8 Oct. That, and Dr John Stockton's followup post, should answer any
question you may have regarding dates - oh, and look at the FAQ:

<URL:http://www.jibbering.c om/faq/>

Dr. J also suggests looking at;

<URL:http://www.merlyn.demo n.co.uk/js-index.htm>

Fred.
Jul 23 '05 #2
Thanks Fred
"Fred Oz" <oz****@iinet.n et.auau> wrote in message
news:41******** *************** @per-qv1-newsreader-01.iinet.net.au ...
Astra wrote:
Hi All

I have a <SELECT> for the month (1 .. 12) and a <SELECT> for the year
(2004
... 2020), do you know of any js validation check I can use to check
whether
these values are older than today's date so that I can bring up a warning,
eg


Do a search on "Re: Date format dd/mm" and a post by Mike Winter on
8 Oct. That, and Dr John Stockton's followup post, should answer any
question you may have regarding dates - oh, and look at the FAQ:

<URL:http://www.jibbering.c om/faq/>

Dr. J also suggests looking at;

<URL:http://www.merlyn.demo n.co.uk/js-index.htm>

Fred.


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 23 '05 #3
On Wed, 27 Oct 2004 12:03:12 +0100, Astra <in**@NoEmail.c om> wrote:
I have a <SELECT> for the month (1 .. 12) and a <SELECT> for the year
(2004 ... 2020), do you know of any js validation check I can use to
check whether these values are older than today's date so that I can
bring up a warning,


You can create two Date objects. The first will have the current date,
whilst the second will be a copy modified to the selected month and year.
A simple comparison with then determine if the input is before the current
month.

/* This assumes that each OPTION element has a number with months
* being 1 to 12, and years being four digits.
*/
function isBeforeDate(fo rm) {
/* The Date object uses zero-order month numbers, hence the -1. */
var month = +form.elements['monthSelect'].value - 1,
year = +form.elements['yearSelect'].value,
now = new Date(),
then = new Date(now);

then.setFullYea r(year, month);

if(then < now) {
// The selected month/year is before the current month/year.
}
return (then < now);
}

<!-- Cancels the submission is the date is before this month. -->
<form ... onsubmit="retur n !isBeforeDate(t his);">

Of course, you can integrate the validation into an existing submission
handler, but the check should only be done at this point. If you did it
when the SELECT elements are changed, you might catch the user in the
middle of changing the date to an acceptable date, doing nothing but
causing frustration.

[snip]

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4
JRS: In article <41********@127 .0.0.1>, dated Wed, 27 Oct 2004
12:03:12, seen in news:comp.lang. javascript, Astra <in**@NoEmail.c om>
posted :
I have a <SELECT> for the month (1 .. 12) and a <SELECT> for the year (2004
... 2020), do you know of any js validation check I can use to check whether
these values are older than today's date so that I can bring up a warning,
eg

user chooses 04 and 2003 or 01 and 2004

OnClick a validate script sees that either of the above are older than
today's date and brings up an alert/doesn't submit the form.

You may require to check more than one attempt during a given actual
month. You appear to guarantee field strings YYYY & MM. Therefore, it
is more effective to compare strings of the form YYYYMM.
with (new Date()) Now = String(getFullY ear()*100 + getMonth() + 1)

if (YrField + MoField < Now) { ... // or <=
Creating unnecessary Date Objects wastes microseconds.

If getFullYear() is not with certainty available, as a short-term
solution you can use 2000 + getYear()%100 .

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #5
On Wed, 27 Oct 2004 22:56:41 +0100, Dr John Stockton
<sp**@merlyn.de mon.co.uk> wrote:

[snip]
You appear to guarantee field strings YYYY & MM. Therefore, it is more
effective to compare strings of the form YYYYMM.
Indeed. I hadn't considered that (though it's quite an obvious solution).

[snip]
Creating unnecessary Date Objects wastes microseconds.
Considering that the only reasonable time to perform this validation is at
form submission, even a delay of an entire second is meaningless.
If getFullYear() is not with certainty available, [...]


This thought (or rather one concerning setFullYear) also crossed my mind,
so I decided to see when Netscape and Microsoft implemented setFullYear:
NN 4.06 and IE 4, respectively. I would assume that other browser vendors
implemented the method, and other similar ones, around that time.

Should the presence of set/getFullYear still remain a concern?

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #6

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

Similar topics

4
2163
by: Gleep | last post by:
Hi PHP coders, I've got an issue I'm stuck with. Imagine there is a large form that has 5 columns and 20 rows. In each row there is a check box - then 4 input fields. I already have the code that inserts all the data BUT the validation is a nightmare. What I need is. If an entire row is empty (not checked or filled out) that's OK....
13
3907
by: David Gray | last post by:
Greetings all, Quick newbie type question: I would like to be able to trap non-numerical data entered into a textbox via CTRL+C and/or Shift+Insert. I realise that this data can be validated using the TEXTn_validate event but I would like to stop the user before it gets that far.
5
5979
by: Steve | last post by:
I am currently trying to validate data in an access database. I need to verify that columns containing date information are in the format ddmmyyyy and columns containg time information are in the format HH:MM 24. The dates and times are stored in text fields. ie date 12121998, time 20:34 Could anyone suggest a method for validating the...
5
2439
by: sourabh | last post by:
Hi I have a basic qus. I am writing a middle-tier component. I have constructor which takes 3 inputs, here's how it looks internal ClassName(Database dbToUse, Int64 pk,DateTime Date) { } Now , i want to know should I validate all the inputs before i start using
1
2885
by: panche | last post by:
I'm developing a fairly simple user control that has two textboxes for date/time entry (a from date/time and a to date/time). One of my requirements is that there should be no button that sets these values (i.e., no button to cause a postback). The problem I'm having is that I need a number of validations to be performed on the data entry,...
3
2192
by: raflex | last post by:
Hello every one: Can some one direct me to a good how-to or tips site that teache how to validate the data the an user in puting on a text field. what i want is some code to prevent the user from inserting numbers on "name" fields or letter on a "date" field. thanks you all for your help >:}....
9
1581
by: xian2 | last post by:
Hi All, I have two fields in my table that need validating in regards to each other. The field names are "TourStartDate" and "TourFinishDate" "TourStartDate" is validated with >Date() And I need to validate "TourFinishDate" so it is later or equal to the value in "TourStartDate"
8
1944
by: Rob Wilkerson | last post by:
Surprisingly (at least to me), there doesn't seem to be a built-in function to validate a date value (like, say, is_date()). Given that, is there a best practice for determining whether a value is a valid date/time? The values I need to test will likely be unix timestamp values and I need to be able to distinguish them as date/time values...
8
13734
vs2k8
by: vs2k8 | last post by:
Hello guys, New to this forum and new to access programing, my issue is I am comparing 2 date fields, I have to validate that Order Rcvd Dt should be less then Ord Comp date and Order Comp date cannot be null. So I written a function to validate the field which is shown below, If I write before update on Order_comp_date field then I get...
0
7521
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...
0
7451
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...
0
7720
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. ...
1
7473
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7810
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...
0
6044
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...
1
5369
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3501
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...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.