CFLib.org – Common Function Library Project

ccEscape(ccnum)

Last updated April 26, 2009

Version: 2 | Requires: ColdFusion 5 | Library: StrLib

 
Rated 2 time(s). Average Rating: 4.5

Description:
Escapes a credit card number, showing only the last 4 digits. The other digits are replaced with the * character.

Return Values:
Returns a string.

Example:

view plain print about
<cfset creditcard="4343010125259797">
<cfoutput>#ccEscape(creditcard)#</cfoutput>

Parameters:

Name Description Required
ccnum Credit card number you want to escape. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Escapes a credit card number, showing only the last 4 digits. The other digits are replaced with the * character.
 * return just stars if str too short, found by Tony Monast
 * 
 * @param ccnum      Credit card number you want to escape. (Required)
 * @return Returns a string. 
 * @author Joshua Miller (josh@joshuasmiller.com) 
 * @version 2, April 26, 2009 
 */

function ccEscape(ccnum){
    if(len(ccnum) lte 4) return "****";
    return "#RepeatString("*",val(Len(ccnum)-4))##Right(ccnum,4)#";
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
3 day(s) ago

Will Belden Will Belden added
longTime
9 day(s) ago

James Sleeman James Sleeman added
quickSort
19 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
22 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson