Closed (fixed)
Project:
Field Validation
Version:
7.x-1.0-beta5
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
9 Nov 2011 at 19:08 UTC
Updated:
11 May 2012 at 10:20 UTC
Hopefully someone can point me in the right direction..
I am trying to validate a "Date" field to reject dates that are not more than a month in the future.. Can you suggest how I could do this?
Thanks..
Comments
Comment #1
wipeout_dude commentedAdding to this as I thought about it.. Would also be great is I could validate that the times were between 8am and 6pm.. :)
Thanks..
Comment #2
g089h515r806 commentedDate module is a vey popular field module.
Maybe we will add more support for it in the future, I do not know which the common validation rule is needed for date field.
Comment #3
g089h515r806 commentednow it could be done through "Custom PHP function" validation. this article maybe helpfull for you,http://drupal.org/node/1325068 .
you need a little change to use it.
Comment #4
g089h515r806 commentedAdd date range validator for date module.Here is the document:
http://drupal.org/node/1438436
Here are some examples of date range:
{global}[2012-02-10 08:30:00, 2012-02-13 20:30:00]
{year}(02-10 08:30:00, 02-13 20:30:00]
{month}(07 08:30:00, 13 20:30:00)
{week}(1 08:30:00, 5 20:30:00)
{day}[08:30:00, 20:30:00)
{hour}[10:00, 35:00]
{minute}[00, 35]
{global}[now, +1 month]
It also support:
{global}[2015-02-10 08:30:00, 2012-02-13 20:30:00]
{year}(11-10 08:30:00, 02-13 20:30:00]
{month}(22 08:30:00, 06 20:30:00)
{week}(6 08:30:00, 0 20:30:00)
{day}[22:30:00, 08:30:00)
{hour}[50:00, 10:00]
{minute}[55, 15]
Comment #5
henryblyth commentedFor those wondering about the difference between using [, (, ], and ) around the start and end dates, and the use of reversing the start and end values:
Before the start date, or after the end date, a square bracket [ ] means 'inclusive'. A parenthesis ( ) means 'exclusive'.
As an example:
{day}[22:30:00, 08:30:00) will not validate (due to reversing the values) if the submitted time value is inside the range of 08:30:01 to 22:30:00.
Note that 08:30:01 (one second past the required value) is exclusive to 08:30:00 whereas 22:30:00 is inclusive.
So, a submitted value that evaluates to a time of 08:30:00 is valid. However, 22:30:00 is invalid.
Reversing the values is effectively a not '!' operator upon the entire calculation. It is the last check to occur, so one's thought process should evaluate the range given, including the information above regarding inclusive/exclusive values, then 'not' the result.
Thanks g089h515r806 for this addition! Could you add this info to this project's documentation so it becomes more visible to others? (Assuming I have it correct of course!)
Cheers,
Henry Blyth
Comment #6
g089h515r806 commentedDo you mean there is a logic error at {day}[22:30:00, 08:30:00)
I have not test it when the value is 22:30:00 or 08:30:00,
This is my understanding for {day}[22:30:00, 08:30:00)
valid values:
22:30:00
22:30:01
22:30:02
...
08:29:58
08:29:59
Unvalid values:
08:30:00
08:30:01
08:30:02
...
22:29:58
22:29:59
If it does not work as this, that means the there is a error for the logic.
Comment #7
g089h515r806 commented{day}(22:30:00, 08:30:00) means reverse of {day}[08:30:00,22:30:00]
{day}(22:30:00, 08:30:00] means reverse of {day}(08:30:00,22:30:00]
{day}[22:30:00, 08:30:00) means reverse of {day}[08:30:00,22:30:00)
{day}[22:30:00, 08:30:00] means reverse of {day}(08:30:00,22:30:00)
Comment #8
g089h515r806 commented{day}(22:30:00, 08:30:00) means reverse of {day}[08:30:00,22:30:00]
{day}(22:30:00, 08:30:00] means reverse of {day}(08:30:00,22:30:00]
{day}[22:30:00, 08:30:00) means reverse of {day}[08:30:00,22:30:00)
{day}[22:30:00, 08:30:00] means reverse of {day}(08:30:00,22:30:00)
Comment #9
g089h515r806 commentedI have test it with latest code, the logic of the code is right.
Maybe i need write a document for this feature, it is a little difficult to understand it
Comment #10
henryblyth commentedSorry g089h515r806, I didn't mean to cause confusion. I was explaining how I thought the logic worked - there wasn't an error.
In post #6 you explain it more succinctly. And yes, please write a document for this feature. I figured it out from my own testing, so it would be useful to others.
Thanks again,
Henry
Comment #11
g089h515r806 commented