> I'm passing the date entered and the date mask. The UDF pulls out the
> value of the date (day, month and year fine) but I want to be able to
> check to see if it is a legal day and month before making it into an
> ODBC date.
>
> So I'm doing something like this:
>
> Check to see what mask is wanted:
>
> Grab the digits up to the first / and put in day, month or year, depending
> on mask. Repeat for up to send /, and finally for last piece of data.
>
> Now if there aren't enough slashes or if the day or month isn't legal, I'd
> like to display and error and drop out of the cfscript block without
> converting to ODBC date.
>
> I used to do this in straight CF code and used a javascript pop up to
> display the error.
Are you checking the mask due to the possibility of the day and month being inverted ?
i.e. mm/dd/yyyy vs. dd/mm/yyyy? ... If so, you should be able to get away with no more
than about 2 if's in a user-defined function...
function validDate(mydate) {
if (not ReFind(mydate,"[0-9][0-9]?/[0-9][0-9]?/[0-9][0-9][0-9][0-9]")) {
return "Inavlid Date Mask"; }
var day = listfirst(mydate,"/");
var month = listgetat(mydate,2,"/");
var year = listlast(mydate, "/");
tempdate = CreateDate(year,month,1);
if (day gt daysinmonth(tempdate)) { return "Date exceeds days in month."; }
return CreateDate(year,month,day);
}
then all you have to do is use the function:
<cfoutput>#validDate(form.mydate)#</cfoutput>
and of course, IsDate(validDate(form.mydate)) will tell you if the validation result
produced an error...
hope this helps,
Isaac
www.turnkey.to
954-776-0046
______________________________________________________________________
Signup for the Fusion Authority news alert and keep up with the latest news in
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists