WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Validation UDFs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Validate IP Address


#DefineFunction CheckIPAddress(szAddr)
	;Check string is no longer than 15 characters
	if StrLen(szAddr)>15
	  ;Message("NOTE","Not a valid ip address")
	  Return @False
	endif
	
	;Check there are 4 octets in the string
	OctetCount = ItemCount(szAddr, '.')
	if OctetCount <> 4
	  ;Message('Error', 'Malformed IP address')
	  Return @False
	endif

	for i = 1 to 4
	  Octet = ItemExtract(i, szAddr, '.')
	  if Octet < 0 || Octet > 255 || !IsNumber(Octet)
	    ;Message('Not Valid IP Address', StrCat('Octet #', i, ' is not numeric between 0 and 255')
		 Return @False
	  endIf
	next 

   Return @true
#EndFunction

ipaddr = "111.222.111.222" ;Valid address
;ipaddr = "111.256.111.256" ;Invalid address 
ret = CheckIPAddress(ipaddr)
if ret
	Message(ipaddr,'Is A Valid IP Address')
else
	Message('Error','Not Valid IP Address')
endif

Article ID:   W16743
File Created: 2005:02:18:12:22:10
Last Updated: 2005:02:18:12:22:10