Re: Validate a date ? - Illustra Web Blade
Posted in 1997
Topics: Storage & Space Management, Stored Procedures & SPL
On Sun, 16 Mar 1997, Rob Acraman wrote: > moore <mmoore@antares.Tymnet.COM> writes: > > >I am using Illustra with Web Data Blade. It seems that there is > >no easy way to accept a date from a web page and determine > >if it is a valid date. (Apply a date edit). > >I would expect a $(ISDATE,value) function but there is none. > >Also there seems to be no date validation function in the > >Illustra User's Guide. > > >Am I missing something? It seems to me that this is pretty > >basic! What is the best way to validate a date. > > You could set up an <?MIERROR> tag to catch an exception, then try something like <?MiSQL SQL="return > $datefld::date;" ERROR=DateErr>. Yes, I did try something like this. Here is the code. ------------------------------------------------------- <HTML> <HEAD> <TITLE>SQL Functions Test</TITLE> </HEAD> <BODY background=<?MIVAR>$WEB_HOME<?/MIVAR>?LO=I0103802414738&type=image/jpeg> <?MIERROR ERR=BADDT TAG=MISQL SQL="return lower('bad_date');"> $1<?/MIERROR> <CENTER><h2>TESTING SQL FUNCTIONS</H2></CENTER><HR> Valid date test. Hard coded date is tested as valid or not. In a real situation, that hard-coded date would be a variable received from a FORM INPUT field.<HR> <?MISQL ERR=BADDT SQL="return date '1997-02-29';">$1<?/MISQL> <HR>If the date is not valid, this text, nor the text above will be rendered,.... only the output of the MIERROR block will be shown. This is NOT what I want, I want this text to be shown Plus the text generated by the MIERROR BLOCK. </BODY> </HTML> ------------------------------------------------------------------------- In the example above, MIERROR is inoked because Feb does not have 29 days in 1997. "lower" is used because I just needed a function that could return text. When MIERROR is invoked, the resultant display only shows 'bad_date' on a standard grey background. Here is what I want to happen. First the user sees a form like this ------------------------ CUSTOMER NUMBER: ITEM NUMBER: ORDER DATE: [Submit button] ------------------------ They fill it out and hit Submit: ------------------------ CUSTOMER NUMBER: 1219 ITEM NUMBER: 3r54 ORDER DATE: 1997-02-29 [Submit Button] ------------------------ Next they see: ----------------------------------------- CUSTOMER NUMBER: 1219 ITEM NUMBER: 3r54 ORDER DATE: 1997-02-29 [Submit button] - - - - - - - - - - - - - - - - - - Order NOT processed; invalid data ITEM NUMBER: must be numeric ORDER DATE: date is not a valid date ----------------------------------------- So, they see the original form plus the error messages. Creating an APP page that loops to itself when the Select button is hit is *not* a problem. (For those not familiar with APP pages, an APP page is a chunk of source code that allows HTML to be imbedded in it. You can branch to different blocks of code based on the value of variables that are passed from previous itterations of the same App Page.) The ONLY problem is determining if the value in name variable associated with the 'ORDER DATE' field actually contains a VALID date. With the ITEM NUMBER all that I need to write is. <?MIBLOCK COND=$(NOT,$(ISNUM,$item_num))>ITEM NUM: must be numeric. <br><?/MIBLOCK> So what I would expect to be able to do is: <?MIBLOCK COND=$(NOT,$(ISDATE,$order_date))>ORDER DATE: not valid date. <br><?/MIBLOCK> But alas, there is NO $(ISDATE) function. !!! ARGH!! > > However, I think a real problem is wanting users to obediently enter SQL-allowable dates; Whatever you say on > the page, they will always want to type in a date in their own format, and then say your page is unfriendly > if/when it complains! I agree, but for me, in this specific case, I have very few users and they will just have to get used to type in a date as YYYY-MM-DD. > If you know C, try writing a function (say ReturnDate) to take their text, try to > understand it, and return it in legal-SQL-text (it's a bit difficult to actually return a date in binary), and > then use (say): > insert .... values (ReturnDate($datefld)::date, ....) > > Good Luck, > > Rob >