CFLib.org – Common Function Library Project

isBit(x)

Last updated February 14, 2006

author

Mike Tangorre

Version: 1 | Requires: CF5 | Library: DataManipulationLib

Description:
isBit checks to see if a value is 1 or 0. This comes in handy when checking radio button values where you have two radio buttons with bit values. While this does not save a lot of typing, it does help, especially when your form has an abundance of radio buttons, etc.

Return Values:
Returns a boolean.

Example:

<cfset var1 = 1 />
<cfset var2 = "1" />
<cfset var3 = "test string" />
<cfset var4 = "-0" />
<cfset var5 = 000 />
<cfset var6 = arrayNew(1) />
<cfset var7 = 0 />

<cfoutput>
#isBit(var1)# - true<br />
#isBit(var2)# - true<br />
#isBit(var3)# - false<br />
#isBit(var4)# - false<br />
#isBit(var5)# - false<br />
#isBit(var6)# - false<br />
#isBit(var7)# - true<br />
</cfoutput>

Parameters:

Name Description Required
x Value to check. Yes

Full UDF Source:

/**
 * Checks that a value is equal to 1 or 0.
 * 
 * @param x 	 Value to check. (Required)
 * @return Returns a boolean. 
 * @author Mike Tangorre (mtangorre@cfcoder.com) 
 * @version 1, February 14, 2006 
 */
function isBit(x){
   if(isSimpleValue(x) and len(x) eq 1 and (x eq 0 or x eq 1))
      return true;
   else
      return false;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson