Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I add spaces to a Credit card Number upon output? 1

Status
Not open for further replies.

JanetB

Programmer
Oct 10, 2002
9
0
0
US
I am converting a web site from asp code to ColdFusion. I am having difficulty writing CF code to insert spaces in Credit Card numbers so our Customer Support personnel can easily read the numbers. asp code is:
<%
a= Left(rsCustNewOrders(&quot;CreditCardAcctNum&quot;).value, 4)
b= Mid(rsCustNewOrders(&quot;CreditCardAcctNum&quot;).value, 5,4)
c= Mid(rsCustNewOrders(&quot;CreditCardAcctNum&quot;).value, 9, 4)
d= Mid(rsCustNewOrders(&quot;CreditCardAcctNum&quot;).value, 13)
%>
<%=a%>&nbsp;<%=b%>&nbsp;<%=c%>&nbsp;<%=d%>

How can I create the same effect using ColdFusion?
 
<cfset a=left(ccnum,4)>
<cfset d=right(ccnum,4)>
<cfset ccnum=mid(ccnum,5,8)>
<cfset b=left(ccnum,4)>
<cfset c=right(ccnum,4)>

<CFOUTPUT>#a# #b# #c# #d#</CFOUTPUT> ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Thank you, Thank you. This is exactly what I needed.
 
No problem.. Its always good when they keep function names and syntax on a standard... IE: Left,Right,UCase,LCase (and others) exist in CF and VB.. Look at the syntax of mid in both languages here... its the same syntax, the major difference where you say QueryName(&quot;column&quot;) CFers say Queryname.column...

Wish it was all on a standard... ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
You could also just use the Insert() command.

Code:
<CFSET CCNumber = &quot;1234567890123456&quot;>

<CFLOOP index=&quot;whichPos&quot; list=&quot;12,8,4&quot;>
   <CFSET CCNumber = Insert(&quot; &quot;, CCNumber, whichPos)>
</CFLOOP>

<CFOUTPUT>#CCNumber#</CFOUTPUT>

Don't know which way is more intuitive or faster... personally I like Insert a lot better than a bunch of MIDs... but, as webmigit said, I suppose there's something to be said for using similar syntax to VB if that's what you're used to.

Hope it helps,
-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top