Solved

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

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

631 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