Re: Help with validating a date input to a dialog
Re: Help with validating a date input to a dialog
- Subject: Re: Help with validating a date input to a dialog
- From: Michelle Steiner <email@hidden>
- Date: Fri, 30 Mar 2001 19:53:37 -0800
On 3/30/01 7:29 PM, Michelle Steiner <email@hidden> wrote:
>
*nod* It's going to be for me and a friend of mine who uses the standard
>
US date/time format. I do plan to do more error trapping for format,
>
though, but this one can catch a lot of the errors right off the bat and
>
save me from writing a lot of the trapping.
Here it is.
--Michelle
global DateToSend
display dialog (my setthedate("Please enter the date in format
"mm/dd/yyyy"."))
on setthedate(prompt)
set errorPrompt to "Please us the correct format "mm/dd/yyyy"."
set DateToSend to (text returned of (display dialog prompt default
answer ""))
set {tid, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, "/"}
try
date DateToSend
on error
my setthedate(errorPrompt)
end try
set the itemsToCheck to the text items of DateToSend
set checkMonth to text item 1 of itemsToCheck as number
if checkMonth is greater than 12 or checkMonth is less than 1 then
setthedate(errorPrompt)
end if
set checkDate to text item 2 of itemsToCheck
if checkDate is greater than 31 or checkDate is less than 1 then
setthedate(errorPrompt)
end if
set checkyear to text item 3 of itemsToCheck
if length of checkyear is not 4 then
setthedate(errorPrompt)
end if
set text item delimiters to tid
return DateToSend
end setthedate
----------------------------------------------------------------------
| Michelle Steiner | We're not human beings having a spiritual |
| | experience. We're spiritual beings |
| email@hidden | having a human experience. |
----------------------------------------------------------------------