Solved

Validate and Error check text box for a specific date format?

Posted on 2001-07-11
4
743 Views
Last Modified: 2013-12-24
Hello,

I need to validate and error check a text box the user sometimes enters a date in.  I would change the data type to a "date/time" from text, however, the user sometimes needs to enter something other than a date.

Any suggestions?
0
Comment
Question by:cgttsp01
[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 14

Accepted Solution

by:
Scott Bennett earned 100 total points
ID: 6273573

The following code gives and example of how you can use cfform/cfinput to validate the date field. The limitation is that the date must be entered in the following format: mm/dd/yyyy.

---------------------Example Code------------------------
<cfform name="MyForm" action="Action.cfm" method="POST">
     <cfinput name="Date" type="Text" validate="date">
     <input name="Submit" type="Submit" value="Submit">
</cfform>
---------------------End Example--------------------------

However you are saying that the user may also use this field for entering other information. in this case you can either build a complicated java script to validate on client side or you can validate on the server side, using the IsDate() function, as follows:

-------------------Begin Example---------------------------

<!--- Note: This form submits to itself --->

<cfif isDefined("Form.Date")>

     <cfif isdate(Form.Date)>
          Execute code for processing date here
     <cfelse>
          Execute code for processing other data here
     </cfif>
     
<cfelse>

     <cfform name="MyForm" action="Self.cfm" method="POST">
          <cfinput name="Date" type="Text">
          <input name="Submit" type="Submit" value="Submit">
     </cfform>

</cfif>

--------------------------End Example---------------------


Let me know if you need more expplanation.
-Scott

0
 

Author Comment

by:cgttsp01
ID: 6273918
Scott,

Thanks for the example.  How would I differentiate between what "<cfif isDefined("Form.Date")>" and what is not a date, when I submit the form?

Steve
0
 
LVL 14

Expert Comment

by:Scott Bennett
ID: 6274002
"<cfif isDefined("Form.Date")>" just checks for the existence of the form field to see if the form has been submitted.  It doesn't matter what kind of data is in the field. The reason I checked to see if the form is submitted is because the form submits to itself. If  "Form.Date" is not defined then the form has not been sumitted yet so the form will be displayed.

If "Form.Date"  is defined, then the the form HAS been submitted, and the code then further tests the "Form.Date" with the if statement "<cfif isdate(Form.Date)>". The IsDate() function verifies weather the value entered in the field can be evaluated as a date. If the value of "Form.Date" can be evaluated as a date, then the value is processed as a date. Or else it is proccessed as other data.


Let me know if it still doesn't make sense
-Scott
0
 

Author Comment

by:cgttsp01
ID: 6276767
Thanks for your time.
Your suggestion worked fine.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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