Formating String

Posted on 2009-02-20
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

    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

    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

    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)


    Assisted Solution

    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.
    LVL 2

    Assisted Solution

    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.
    LVL 39

    Expert Comment

    textgreen ?

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
    Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
    The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and Log…
    The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now