Solved

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

Posted on 2001-07-11
4
739 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 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

810 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