Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
Joerg
- VIP Livecode Opensource Backer
- Posts: 21
- Joined: Sun Dec 20, 2009 12:35 am
Post
by Joerg » Thu Feb 18, 2010 8:57 pm
Hi,
I have a field, say txtDate, where I would like to validate whether the user has entered a valid date or not:
Code: Select all
set the useSystemDate to true
if fld txtDate is a date then put "true"
else put "false"
When I put a any number into the field then, say 1 or 123 or whatever, the validation results in "true" although it is not a valid date value. What am I doing wrong?
-
BvG
- VIP Livecode Opensource Backer
- Posts: 1236
- Joined: Sat Apr 08, 2006 1:10 pm
- Location: Zurich
-
Contact:
Post
by BvG » Thu Feb 18, 2010 9:29 pm
The "is a date" check is only checking if rev would convert the value to a date. Because of "the seconds", any integer is a date for rev. Every country enters date differently. So to make rev only accept valid dates, I suggest to check for formatting that are according to your local date requirements.
for example:
put field 1 into theDate
set the itemDe ... ans
end if
If you want to be sure I suggest to use a calendar entry widget that pops up, one like most websites use.
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
-
Joerg
- VIP Livecode Opensource Backer
- Posts: 21
- Joined: Sun Dec 20, 2009 12:35 am
Post
by Joerg » Thu Feb 18, 2010 9:48 pm
Obviously I have misunderstood the "is a date" check. Thank you very much for your example. I think I will go with it. Although, using a calendar entry widget would maybe be the better alternative. Would it be possible for you to post a link of such a control because my search within revOnline Samples was not successful?
Thank you very much BvG
Jörg
-
dunbarx
- VIP Livecode Opensource Backer
- Posts: 9752
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Post
by dunbarx » Thu Feb 18, 2010 10:55 pm
That rev can resolve an integer into a date can be both useful and annoying, as you have seen.
You can always say:
if fld "txtdate" is a date and fld "txtDate" is not an integer then...
Craig Newman
-
bn
- VIP Livecode Opensource Backer
- Posts: 4027
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Post
by bn » Thu Feb 18, 2010 11:05 pm
Jörg,
Sarah Reichelt has posted on her website a calender stack. This stack has a substack that lets you choose a date.
http://www.troz.net/rev/index.irev?cate ... ity#stacks
Sarah knows all about dates and time in Rev. She is THE expert.
You have to test it, I did not include it in any of my projects yet, but she explains how to do it.
regards
Bernd
-
BvG
- VIP Livecode Opensource Backer
- Posts: 1236
- Joined: Sat Apr 08, 2006 1:10 pm
- Location: Zurich
-
Contact:
Post
by BvG » Thu Feb 18, 2010 11:10 pm
me too
http://www.bjoernke.com/?target=stacks
about in the middle, date & time
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
-
bangkok
- VIP Livecode Opensource Backer
- Posts: 937
- Joined: Fri Aug 15, 2008 7:15 am
Post
by bangkok » Thu Feb 18, 2010 11:39 pm
Damned ! I spent long time to modify Sarah's stack in order to make it as a group, not a popup window, for a revlet.
But your stack is perfect. I wish I had known it before.
-
BvG
- VIP Livecode Opensource Backer
- Posts: 1236
- Joined: Sat Apr 08, 2006 1:10 pm
- Location: Zurich
-
Contact:
Post
by BvG » Fri Feb 19, 2010 1:01 am
yeah... there should be a central repository where everyone uploads their stacks and hints and such... and then everybody would use it because it'd be rad and such... yeah that'd be nice...
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
-
Joerg
- VIP Livecode Opensource Backer
- Posts: 21
- Joined: Sun Dec 20, 2009 12:35 am
Post
by Joerg » Fri Feb 19, 2010 10:27 am
Thanks to all! I think I will spend a bit of time to try the stacks. BvG, I think you are absolutely right with your suggestion that there should be a central repository. It would help definitely everybody! Craig, your "date-check", the combination of ... is a date ... and ... is not an integer ... is also a good approach but in my case a check of e.g. "14.123456" would result in "true" although this is not a date value is valid. But I think with additional checks (e.g. type of items and length) it would also work.
regards
Jörg
-
bn
- VIP Livecode Opensource Backer
- Posts: 4027
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Post
by bn » Fri Feb 19, 2010 11:10 am
@BvG,
you could post it to RevOnline, that could be a central repository. If only people would use it as such.
regards
Bernd
-
BvG
- VIP Livecode Opensource Backer
- Posts: 1236
- Joined: Sat Apr 08, 2006 1:10 pm
- Location: Zurich
-
Contact:
Post
by BvG » Fri Feb 19, 2010 11:13 am
yes that's what i meant, rev online is there, but it has some backdraws. And the biggest is that people are not using it
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
-
malte
- Posts: 1098
- Joined: Thu Feb 23, 2006 8:34 pm
- Location: Ostenfeld germany
-
Contact:
Post
by malte » Fri Feb 19, 2010 11:38 pm
Schnipp
Joerg wrote:... is not an integer ... is also a good approach but in my case a check of e.g. "14.123456" would result in "true" although this is not a date value is valid. But I think with additional checks (e.g. type of items and length) it would also work.
regards
Jörg
Schnapp
There also is the expression "is a number" which could be more useful in your case. Also for german dates you could set the itemdel to "." and check the number of items (which would need to be 3 and all of them would need to be numbers)
Cheers,
Malte
-
Klaus
- Posts: 13868
- Joined: Sat Apr 08, 2006 8:41 am
- Location: Germany
-
Contact:
Post
by Klaus » Thu Feb 25, 2010 2:43 pm
Hi folks,
on Windows you can use a tiny VBS Script as a workaround:
...
put "result = IsDate(" & QUOTE & the_date_in_question & QUOTE & ")" into tvb
do tvb as vbscript
put the result into is_a_date
## true or false
...
Tested with these (german! DD/MM/YYY) variations of a date:
01/01/1969
31/01/1969
31-01-1969
31.01.1969
31.01.69
01/01/69
31/01/69 ## Obvioulsy also works with english dates!
31-01-69
01/31/1969
31.1.69
Best
Klaus