Solved

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

Posted on 2001-07-11
4
733 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:
SBennett 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:SBennett
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now