Formating String

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.

Who is Participating?
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

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.
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)

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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.
jQuery has great client-side validation.  


When the valid input is submitted, just use the DateFormat() function to insure you get it in mm/dd/yyyy.
textgreen ?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.