CFLib.org – Common Function Library Project

checkAsc(str [, denylist])

Last updated September 23, 2004

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

 
Rated 0 time(s). Average Rating: 0

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:

view plain print about
<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:

view plain print about
<cfscript>
/**
 * 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; 
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

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

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

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

Ben Forta Ben Forta added
GetHostAddress
28 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