Skip to main content
Participating Frequently
June 23, 2009
Answered

Date masking by cflocale

  • June 23, 2009
  • 2 replies
  • 1777 views

I'm trying to create a form in my localised web application which will use the cflocale value to mask a text based date-input field.

I don't want to use a calendar tool as the date selection method, but would like to be able to use something along the following lines:


<cfinput type="text" name="myDate" id="myDate" required="yes" mask="#localeDateMask#" message="Enter a valid date in the format #localeDateMask" validateat="onsubmit,onserver" />

Ideally, I was wondering if I can populate the localeDateMask variable from the underlying java locale setting. Otherwise, I'm going to have to create a look-up table to get this value for each possible locale. No problem doing that, but I'd rather not re-invent the wheel!

    This topic has been closed for replies.
    Correct answer tooMuchTrouble

    guess it got truncated via email gateway. lets see if the web forum works better.

    <cfscript>
    formatStyle=0; // full 0--->3 short
    thaiLocale=createObject("java","java.util.Locale").init("th","TH");
    dF=createObject("java","java.text.DateFormat").getDateInstance(formatStyle,thaiLocale);
    writeoutput("#dF.toPattern()# <br>for example: #df.Format(now())#");
    </cfscript>

    2 replies

    Inspiring
    June 23, 2009

    you mean something like this?

    formatStyle=0; // full 0--->3 short thaiLocale=createObject("java","java.util.Locale").init("th","TH"); dF=createObject("java","java.text.DateFormat").getDateInstance(formatStyle,thaiLocale); writeoutput("#dF.toPattern()#
    ]]>
    for example: #df.Format(now())#");

    </cfscript

    Participating Frequently
    June 23, 2009

    Thanks for your prompt answer, Paul.

    I'm not sure if your example was truncated or I'm being stupid.

    Where is the df variable populated in your example?

    tooMuchTroubleCorrect answer
    Inspiring
    June 23, 2009

    guess it got truncated via email gateway. lets see if the web forum works better.

    <cfscript>
    formatStyle=0; // full 0--->3 short
    thaiLocale=createObject("java","java.util.Locale").init("th","TH");
    dF=createObject("java","java.text.DateFormat").getDateInstance(formatStyle,thaiLocale);
    writeoutput("#dF.toPattern()# <br>for example: #df.Format(now())#");
    </cfscript>

    Participating Frequently
    June 23, 2009

    <cfinput type="text" name="myDate" id="myDate" required="yes" mask="#localeDateMask#" message="Enter a valid date in the format #localeDateMask#" validateat="onsubmit,onserver" />