I have a DueDate which will be provided as text string in one of the following formats:
- as proper date, e.g. ‘12/09/2013’ or ‘12-9-13’
- as number of days or weeks, e.g. ‘3d’ (in 3 days), ‘-10d’ (= 10 days ago), ‘2w’ (= in 2 weeks)
- as ‘today’
- as ‘tomorrow’
(The script later converts the #d/#w syntax/today/tomorrow into a date string, no questions on that part).
What I need is a code snippet, that validates that the provided DueDate text string is u conform with one of above shown, accepted formats[/u], so that the overall script doesn’t fail if the provided DueDate text string is either incomplete or contains any typos. This is what I have in mind:
try
date (theDueDate) -- Test #1. This line works and reliably tests whether the DueDate is readable as date
-- but these three formats must be accepted as OK as well
OR (any negative or positive integer number)(ANY quantity, so 0 to infinity, of accidental spaces in-between, which would be OK)(a SINGLE occurrence of the character d, t or w) -- Test #2. How?
OR 'today' -- Test #3. How?
OR 'tomorrow' -- Test #4. How?
set ValidDueDate to true
on error
set ValidDueDate to false
end try
How to combine all four test, so that any of the four tests would lead to ‘true’? How to code tests #2, #3 and #4?
Model: MacBook Pro 13"
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)