Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

date validation in coldfusion 7

Posted on 2009-07-08
4
Medium Priority
?
405 Views
Last Modified: 2013-12-24
hi, i have tow dates, Start date and end date. if user selects start date as 07/01/09 and end date as 07/08/09, then it's valid. but right now my code doesn't validate if user enters start date as 07/15/09 and end date as 07/10/09. end date must have to be a future date (or grater then start Date). how can i validate this in coldfusion. all i need a server side validation. see the action script below, which enables user to select date from today to future. the script is fine, but i need server side validation for user, so that an end date must have to be grater then start date. please provide some code or references.
<cfoutput>		
			<cfformitem type="script">
	                function runOnLoad() 
	                {
	                        var dateString = "#dateFormat(now(), 'yyyy-mm-dd')#";
	                        var startAfter = mx.formatters.DateFormatter.parseDateString(dateString);
	                        start_date.selectableRange={rangeStart: startAfter};    
							end_date.selectableRange={rangeStart: startAfter}; 
	                }
	        </cfformitem>
		</cfoutput>

Open in new window

0
Comment
Question by:khan02
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 24806101
Do you mean CF code (server) or cfform actionscript (client)?

For server side, you can use the DateCompare() function to determine if the startDate is _greater_ than the endDate.

<!--- should also validate values are valid date strings --->
<cfset form.startDate = "07/15/2009" >
<cfset form.endDate = "07/10/2009">

<!--- if startDate is GREATER than endDate --->
<cfif dateCompare(form.startDate, form.endDate) eq 1>
      StartDate cannot be greater than EndDate
<cfelse>
       Okay. StartDate is less than or equal to EndDate
</cfif>
0
 

Author Comment

by:khan02
ID: 24808050
i am so grateful that you have replied so quick, i just realized that, i do need client side validation as well.

the above code you send is for server side validation. can you provide me code for client side validation as well.

regards
khan

thank you once again.
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 24809253
I assume you are using two "datefields"?  If so you can grab the "selectedDate" values.  The value is already a "Date" object. So you should be able to compare them using the  > operator.
<cfform name="x" format="flash" onLoad="runOnLoad()" onsubmit="return CheckDates();">
	<cfoutput>              
	<cfformitem type="script">
		function CheckDates() 
		{
			if (start_date.selectedDate != undefined && end_date.selectedDate != undefined) 
			{
				if (start_date.selectedDate > end_date.selectedDate) 
				{
					alert("StartDate cannot be GREATER than EndDate");
					return false;
				}
			}
			return true;
		}
		
    	function runOnLoad() 
        {
        	var dateString = "#dateFormat(now(), 'yyyy-mm-dd')#";
            var startAfter = mx.formatters.DateFormatter.parseDateString(dateString);
            start_date.selectableRange={rangeStart: startAfter};    
            end_date.selectableRange={rangeStart: startAfter}; 
            }
	</cfformitem>
    </cfoutput>
	<cfinput type="datefield" name="start_date">
	<cfinput type="datefield" name="end_date" value="2009-07-10">
	<cfinput type="submit" name="submitButton">
</cfform>

Open in new window

0
 

Author Closing Comment

by:khan02
ID: 31601225
grate solution...thank you very much
0

Featured Post

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question