CFLib.org – Common Function Library Project

IsInt(varToCheck)

Last updated April 10, 2002

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

 
Rated 1 time(s). Average Rating: 4.0

Description:
Why doesn't CF have a function for checking to see if something is an integer? isNumeric() is all well and good, but sometimes you need an int and you want to check. Well, here's one way to do it.

Return Values:
Returns a Boolean.

Example:

view plain print about
<table border="1">
<cfoutput>
<cfloop list="1,1.4,abc,ab12,12ab,1 2 3,12 abc 34,42" index="var">
<tr>
    <td>#var#</td>
    <td>#YesNoFormat(isInt(var))#</td>
</tr>
</cfloop>
</cfoutput>
</table>

Parameters:

Name Description Required
varToCheck Value you want to validate as an integer. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Checks to see if a var is an integer.
 * version 1.1 - mod by Raymond Camden
 * 
 * @param varToCheck      Value you want to validate as an integer. 
 * @return Returns a Boolean. 
 * @author Nathan Dintenfass (nathan@changemedia.com) 
 * @version 1.1, April 10, 2002 
 */

function isInt(varToCheck){
  return isNumeric(varToCheck) and round(varToCheck) is vartoCheck;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
4 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