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.

Thanks
TrexgreenAsked:
Who is Participating?
 
duncancummingCommented:
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
	<cfabort>
</cfif>

Open in new window

0
 
Tomarse111Commented:
You can easily format the date once it has been submiting using DATEFORMAT or LSDATEFORMAT for example:

#LsDateformat(Form.DOB,"DD/MM/YYYY")#

To be honest with you though I would use Javascript to validate the actual date format before submission.
0
 
gdemariaCommented:
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.

http://www.javascriptkit.com/script/script2/validatedate.shtml

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)

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

 
chowdhury_sanjoyCommented:
Try this code

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

If your form contains a valid date then it will surely convert in mm/dd/yyyy format.
0
 
clickitysplitCommented:
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.
0
 
gdemariaCommented:
textgreen ?
0
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.