CFLib.org – Common Function Library Project

checkAsc(str[, denylist])

Last updated September 23, 2004

author

Tjarko Rikkerink

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Only allow the ASCII text characters (33 to 126) for a certain string, you can also give a list of character numbers for the characters you also want to deny in the string.

Return Values:
Returns a boolean.

Example:

<cfset str = "ci.rcle">
<cfset denylist = "44,46,59,64,124">
<cfoutput>
    #CheckAsc(str,denylist)#
</cfoutput>

Parameters:

Name Description Required
str String to check. Yes
denylist Additional list of codes to deny. No

Full UDF Source:

/**
 * Only allow ASCII text string.
 * 
 * @param str      String to check. (Required)
 * @param denylist      Additional list of codes to deny. (Optional)
 * @return Returns a boolean. 
 * @author Tjarko Rikkerink (tjarko@ditadres.com) 
 * @version 1, September 23, 2004 
 */
function checkAsc(str){ 
    var i = 1;
    var nr = "";
    var denylist = "";
        
    if(arrayLen(arguments) gte 2) denylist = arguments[2];
    while (i LTE len(str)) { 
        nr = asc(mid(str,i,1)); 
        if (nr LT 33 OR nr GT 126 OR listFind(denylist,nr)){
            return false;
        } 
        i = i + 1; 
    } 

    return true; 
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson