Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2001-07-11
4
Medium Priority
?
750 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
  • 2
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
Scott Bennett earned 400 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

971 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