IsValidIP Method

The IsValidIP method is used to determine whether a string represents a properly formatted IP address.

Syntax:

 IsValid = chObj.IsValidIP ipAddrAsStr

Returns:

True if ipAddrAsStr represents a properly formatted IP address, or False if not.

Note: This method tests whether ipAddrAsStr contains 4 octets that are within the range of 0 to 255, with each 'octet separated by '.' characters, and contains only digits. Note that by definition here, a valid IP means that the string is formatted correctly, and not necessarily that the IP address represents a reachable node on the internet. For example, "1.2.3.4" is a valid IP address by format so this method returns True for this value, despite the fact that this is not a reachable IP address.

Example:

set chObj = Server.CreateObject("cyScape.countryObj")

'Returns true

isValid = chObj.IsValidIP "207.46.230.220"

'The following would all return false

isValid = chObj.IsValidIP "207.46.230" 'does not contain 4 octets

isValid = chObj.IsValidIP "207.46.230.220a" 'contains non-numeric chars

isValid = chObj.IsValidIP "256.10.10.1" ' cannot be greater than 255

isValid = chObj.IsValidIP "" ' cannot be blank

Tip: Before calling the Initialize method, use the IsValidIP method to make sure the IP address is valid. Otherwise the Initialize method will raise a run-time error that needs to be caught.

Tip: See the ch_initialize.asp sample for more information.

See the ch_initialize.asp sample for more information.

See Also:

About the Properties and Methods Guide

CountryCode property

RegionCode Property

IPAddr property

Initialize method

CountryName method

RegionName Method

GetSelectList method

IsRestricted method

RegionNameFromCountryCode Method

IsInList method

About the sample scripts