Formating String

Posted on 2009-02-20
Medium Priority
Last Modified: 2013-12-20
I wouldl ike to know how can I format a string that is passed by a form.

I have a form that is generated dynamic, and one of the fields DOB I need to make sure that the input if formated correct.

Is there a way to check if the inputed DOB is in this format 99/99/9999 if not can I format the input to be in that format?

The problem is that I'm using JQuery to add some fields dynamic to my form, and when I do that I cannot use the cfinput mask.

Question by:Trexgreen
LVL 16

Accepted Solution

duncancumming earned 300 total points
ID: 23695571
There's a few ways you could do this.  The simplest way would maybe be  use the IsDate() function or perhaps ParseDateTime()

<cfif NOT IsDate(Form.DOB)>
	Please enter the date like dd/mm/yyyy

Open in new window

LVL 15

Assisted Solution

Tomarse111 earned 300 total points
ID: 23699107
You can easily format the date once it has been submiting using DATEFORMAT or LSDATEFORMAT for example:


To be honest with you though I would use Javascript to validate the actual date format before submission.
LVL 39

Assisted Solution

gdemaria earned 200 total points
ID: 23700360
Option 1:  Use three seperate SELECT tags next to each other; one for month, date and year.   When the user submits, just append the values together and then test using isDate() function.

Option 2: Use javascript to do some testing on the format either onChange or OnSubmit or perhaps both.  Then test the date using isDate() after it is submitted.


Note that both options require you to test the date after it is submitted.  Client-side validation or the select tags could still allow a bad date through (Feb 29 in a non-leap year perhaps)

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments


Assisted Solution

chowdhury_sanjoy earned 300 total points
ID: 23710398
Try this code

<cfif IsDate(Form.DOB)>
<cfset form.DOB = DateFormat(Form.DOB, "mm/dd/yyyy")>

If your form contains a valid date then it will surely convert in mm/dd/yyyy format.

Assisted Solution

clickitysplit earned 300 total points
ID: 23723955
jQuery has great client-side validation.  

See:  http://www.coldfusionjedi.com/index.cfm/2009/2/9/An-introduction-to-jQuery-and-Form-Validation

When the valid input is submitted, just use the DateFormat() function to insure you get it in mm/dd/yyyy.
LVL 39

Expert Comment

ID: 23778174
textgreen ?

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
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 …
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

840 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