isMod10(number)
Last updated October 2, 2008
Version: 3 | Requires: ColdFusion 5 | Library: UtilityLib
Description:
Checks a string against the Luhn Algorithm. Also known as the mod10 algorithm. this function can be used to check the validity of credit card numbers, Canadian social insurance numbers, and any other number as well.
Return Values:
Returns a boolean.
Example:
<cfif IsMod10("4000300020001000")>
This string has passed the mod10 check
<cfelse>
This string has failed the mod10 check
</cfif>
</cfoutput>
Parameters:
| Name | Description | Required |
|---|---|---|
| number | String to check. | Yes |
Full UDF Source:
<cfscript>
/**
* Checks to see whether a string passed to it passes the Luhn algorithm (also known as the Mod10 algorithm)
* V2 update by Christopher Jordan cjordan@placs.net
* V3 update by Peter J. Farrell (cjordan@placs.netpjf@maestropublishing.com)
*
* @param number String to check. (Required)
* @return Returns a boolean.
* @author Scott Glassbrook (cjordan@placs.netpjf@maestropublishing.comcflib@vox.phydiux.com)
* @version 3, October 2, 2008
*/
function isMod10(number) {
var nDigits = Len(arguments.number);
var parity = nDigits MOD 2;
var digit = "";
var sum = 0;
var i = "";
for (i=0; i LTE nDigits - 1; i=i+1) {
digit = Mid(arguments.number, i+1, 1);
if ((i MOD 2) EQ parity) {
digit = digit * 2;
if (digit GT 9) {
digit = digit - 9;
}
}
sum = sum + digit;
}
if (NOT sum MOD 10) return TRUE;
else return FALSE;
}
</cfscript>
Search CFLib.org
Latest Additions
Shawn Porter added
DeMoronize
2 hour(s) ago
Chris Carey added
readPropertiesFi...
1 day(s) ago
Randy Johnson added
lastDayofWeek
3 day(s) ago
Frank Marion added
sitemapPing
7 day(s) ago
Top Rated
QuickSort
Rated 5.0, 3 time(s)
indentXml
Rated 5.0, 3 time(s)
queryColumnsToSt...
Rated 5.0, 3 time(s)
generateSsccAsn
Rated 5.0, 3 time(s)