• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 397
  • Last Modified:

How do I create a Coldfusion text custom format of XXXXXXXX-XXXX

I need to create a Coldfusion text custom format of XXXXXXXX-XXXX.  Is Javascript the only way?  Can someone post a similar example?

Thanks.
0
dkbailey1
Asked:
dkbailey1
  • 8
  • 7
  • 3
1 Solution
 
bwasyliukCommented:
I assume you are talking about form input?

Have you tried the Mask attribute of CFInput?

<cfinput type="text" name="example" mask="XXXXXXXX-XXXX" />

According to the documentation, the X means you want to allow A-Z, a-z, and 0-9
0
 
ExpertAdminCommented:
bwasyliuk,

Didn't see your post until I submitted mine. Exactly what I was going to suggest, but you beat me to it.

M@
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
dkbailey1Author Commented:
bwasyliuk,

Got the following error message when I tried the masking:

Context validation error for tag CFINPUT.  
The tag must be nested inside a CFFORM tag.  
 
Any ideas?

Thanks.
0
 
dkbailey1Author Commented:
Changed my form to cfform but the masking isn't working.
0
 
bwasyliukCommented:
Can you view source on the page and "cut-and-paste" into here the code for the field that you have the mask set on?
0
 
dkbailey1Author Commented:
<INPUT TYPE="text" NAME="logbookWON">

It looks like the masking is not being written into the page.
0
 
ExpertAdminCommented:
So you are not getting an error now?

M@
0
 
dkbailey1Author Commented:
No.  But the masking is not working.  I supposed that the mask should be written to the page, but according to the above 'paste', the mask definition is not being written out to the page.

Any ideas?
0
 
bwasyliukCommented:
I just created a test form using the above <cfinput that I posted:

<cfform name="test" action="post">
<cfinput type="text" name="example" mask="XXXXXXXX-XXXX" />
</cfform>

This works as expected, when you type in a value, the dash "-" is inserted for you, and you cannot type past the length of the string defined in the mask.

The code the CF outputs (when I view the source) is:

<input name="example" id="example" type="text" onkeyup="mask_onValueChanged();" onfocus="mask_onSetFocus(this, 'XXXXXXXX-XXXX');" onblur="mask_onKillFocus();" />
0
 
dkbailey1Author Commented:
My webpage when submit button is clicked, submits itself.  So my action ="mywebpagename", where you are using 'post'.  I wonder if that has something to do with it.
0
 
bwasyliukCommented:
I was just typing a quick example, action="post" doesnt even make sense.

The fact that it is a cfform is what triggers the validation scripts to be added.

Both
<cfform name="test">
<cfinput type="text" name="example" mask="XXXXXXXX-XXXX" />
</cfform>

AND
<cfform name="test" action="myotherpage" method="get">
<cfinput type="text" name="example" mask="XXXXXXXX-XXXX" />
</cfform>

will work.
0
 
bwasyliukCommented:
Can you share your updated form code?
0
 
dkbailey1Author Commented:
Here is my CFFORM code:

 <cfform name = "newLogbook" action = "addLogbook.cfm" method = "post">
  <table border="0" cellspacing="0" cellpadding="2">
 
   <tr>
      <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Logbook SN:</font><br>
            <input name = "logbookSN" type = "text" class="formFields" size = "15">
      </td>
   </tr>
   
   <tr>
      <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">TMS:</font><br>
            <select class = "formFields" name = "TMS">
                       <option value = ""></option>
                        <cfoutput query = "qTMS" group="TMSCatagory">
                              <optgroup label="#qTMS.TMSCatagory#" class="#qTMS.TMSCatagory#">
                                    <cfoutput>
                                             <option value = "#qTMS.TMSID#">#TMS#</option>
                                    </cfoutput>
                              </optgroup>
                        </cfoutput>
               </select>
      </td>
   </tr>
   
   <tr>
      <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">JON:</font><br>
            <input name = "logbookJON" type = "text" class="formFields" size = "10">
      </td>
   </tr>
   <tr>
      <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">WON:</font><br>
<!---      <input name = "logbookWON" type = "text" class="formFields" size = "15" onChange="return jsValidateWON();">  --->
<cfinput type="text" name="logbookWON" mask="XXXXXXXX-XXXX"/>
      <br>
      <span class="style1">Format:  XXXXXXXX-XXXX</span>
      </td>
   </tr>
         
   <tr>
      <td><input name = "submit" type = "submit" class="formButton" value = "Add Logbook"></td>
   </tr>
   
  </table>
  <br>
  <br>
 
</cfform>
0
 
bwasyliukCommented:
I cut and pasted this into a page on my server - and it works great.  Runs exactly as expected.

Is this the whole page, or is there something else going on?  

Which version of CF are you using?
0
 
dkbailey1Author Commented:
Its not the whole page, just the CFFORM.  We are on version 6,1,0,63958.  Do we need to be using a later version?
0
 
bwasyliukCommented:
AAAAAAHHHHHHHHHH

the Mask attribute was added in MX 7

I guess you will need to use your own javascript or use

<cfinput type="text" name="example" validate="regex" pattern="" />

which was available in your version of CF.

The regex pattern value would of course not be blank - you would need to build the regular expression to match the input that you want.
0
 
dkbailey1Author Commented:
Ok, thanks!  I have a crude little Javascript built.  Tried your last suggestion, but it didn't work.  Its time to move on, you get the points. Have a good day!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now