– Common Function Library Project


Last updated July 17, 2001


Nathan Dintenfass

Version: 1 | Requires: CF5 | Library: StrLib

Performs a regex on the string and determines if it a valid IP address. The value passed must match contain four octets delimited by a period. Each octet must be a number from 1 to 255. The addresses and are not valid. <B>Note</B> This only checks the octet form of IP addresses. It does not check the binary form.

Return Values:
Returns a boolean.


<CFSET BADIP = "fred">
<CFSET IP = "">
Is #BADIP# valid? #IsIP(BADIP)#<BR>
Is #BADIP2# valid? #IsIP(BADIP2)#<BR>
Is #IP# valid? #IsIP(IP)#<BR>


Name Description Required
string String to be checked. Yes

Full UDF Source:

 * Returns TRUE if the string is a valid IP address.
 * @param string 	 String to be checked. 
 * @return Returns a boolean. 
 * @author Nathan Dintenfass ( 
 * @version 1, July 17, 2001 
function isIP(ip){
	var ii = 1;
	//make sure it is a '.' delimited list 4 long
	if(listlen(ip,".") is not 4) return false;

	//make sure each item is a number between 1 and 255
	for(ii = 1;ii lte 4;ii = ii + 1){
		if(not isnumeric(listgetat(ip,ii,".")) OR listgetat(ip,ii,".") GT 255 OR listgetat(ip,ii,".") LT 0)	return false;
	//check for the special cases of or, which is not really valid
	if(ip is "" OR IP is "") return false;
	return true;
blog comments powered by Disqus


Latest Additions

Kevin Cotton added
May 5, 2016

Raymond Camden added
April 25, 2016

Chris Wigginton added
January 18, 2016

Gary Stanton added
November 19, 2015

Sebastiaan Naafs - van Dijk added
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson