CFLib.org – Common Function Library Project

isVIN(v)

Last updated August 16, 2008
Download UDF

author

Christopher Jordan Christopher Jordan

Version: 1 | Requires: ColdFusion 8 | Library: StrLib

Description:
This function accepts a Vehicle Identification Number (VIN) as the sole argument, and returns true if the VIN is valid. I don't know if VINs work the same in other countries (I'm in the US), so if anyone knows of any changes necessary to make this work in other locals, please feel free to submit them.

Return Values:
Returns a boolean.

Example:

<cfif IsVIN("1B7HF16Y45S263197")>
    <!--- do something cool... --->
<cfelse>
    <!--- point and laugh at the user. --->
</cfif>

Parameters:

Name Description Required
v VIN number to validate. Yes

Full UDF Source:

<cfscript>
/**
* Vehicle Identification Number validation.
*
* @param v      VIN number to validate. (Required)
* @return Returns a boolean.
* @author Christopher Jordan (cjordan@placs.net)
* @version 1, August 16, 2008
*/

function isVIN(v) {
    var i = "";
    var d = "";
    var f = "";
    var p = "";
    var cd = "";
    var LL    = "A,B,C,D,E,F,G,H,J,K,L,M,N,P,R,S,T,U,V,W,X,Y,Z";
    var VL    = "1,2,3,4,5,6,7,8,1,2,3,4,5,7,9,2,3,4,5,6,7,8,9";
    var FL    = "8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2";
    var rs    = 0;
    
    if(len(v) != 17) {return false;}
    for(i = 1; i
<= 17; i++){
        f = ListGetAt(FL, i);
        d = Mid(v,i,1);
        if(IsNumeric(d)){
            d *= f;
        }
        else{
            p = ListFindNoCase(LL,d);
            d = ListGetAt(VL,p);
            d *= f;
        }
        rs += d;
    }
    cd = rs % 10;
    if(cd == 0){cd = "x";}
    if(cd == Mid(v,9,1)){return true;}
    return false;
}
</cfscript>

Search CFLib.org


Latest Additions

Jose Diaz-Salcedo Jose Diaz-Salcedo added
cfRssFeed
1 day(s) ago

Raymond Compton Raymond Compton added
structBlend
22 day(s) ago

Duncan Duncan added
IsZIPUK
22 day(s) ago

Todd Sharp Todd Sharp added
getTagContentAll
28 day(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Created by Raymond Camden / Design by Justin Johnson