pm_Checker:: ip_address Method

Checks whether the specified IP address satisfies the selected validation rule and IP format.

Syntax

public static function ip_address ($str, $valid, $valid_formats)

Parameters

str

      A string value that specifies the IP address to check.

valid

      A string value that specifies the validation rule to apply. Is set to IP_ADDRESS_ANY by default. The following validation rules are available:

valid_formats

      A string value that specifies the allowed IP address format. Is set to IP_ADDRESS_ANY_FORMAT by default. The following formats are available:

Returns

A boolean which is true if the checked IP address satisfies the validation rule(s) applied and is formatted as specified by the valid_formats constant. Otherwise returns false.

Remarks

This function validates the passed in IP address based on two constants that specify the format of the IP address and the validation rule(s) that should be applied to discover whether the IP address in focus really matches this format.

Here is the table of the admissible combinations of the validation rules and formats:

Format

IP_ADDRESS_

MASK_FORMAT

IP_ADDRESS_

BLOCK_FORMAT

IP_ADDRESS_

NETMASK_FORMAT

IP_ADDRESS_

FORMAT

Validation rule(s)

IP_ADDRESS_BLOCK

yes

yes

yes

no

IP_ADDRESS_NETMASK

no

yes

yes

no

IP_ADDRESS

yes

yes

yes

yes

IP_ADDRESS_BLOCK| IP_ADDRESS_NETMASK| IP_ADDRESS

yes

yes

yes

no

IP_ADDRESS_BLOCK| IP_ADDRESS_NETMASK

yes

yes

yes

no

IP_ADDRESS_NETMASK| IP_ADDRESS

yes

yes

yes

no

IP_ADDRESS_BLOCK| IP_ADDRESS

yes

yes

yes

no

 

The validation rule(s) to apply is (are) specified in the valid parameter. They work as follows:

The valid_formats parameter informs the function what IP address format is validated.