Class: IpValidator

sogv.IpValidator

Validates that a value is a valid IP address.

By default, this will validate the value as IPv4, but a number of different options exist to validate as IPv6 and many other combinations.

new sogv.IpValidator (data, options, optionRules, lang, internal)

Create a new Validator.

Name Type Description
data * The data which needs to be validated.
options Object The setting options
optionRules Object The validation rules for setting options.
lang String The language used by the application. Default: "en".
internal Boolean If this parameter is true, it means, that validation called from core.
Properties:
Name Type Description
alias Array

The aliases for the current validator.

They could be used in the short validation format.

Defined aliases: ['ip'].

options Object The description of the required options.
Example
var validator = new sogv.IpValidator(data);
if (false === validator.isValid()) {
     validator.errors().first();
}

Extends

Members

data * inherited

Data that needs to be validated.

lang String inherited

Language of error messages.

message String

This message is shown if the string is not a valid IP address.

Default: "This is not a valid IP address."

You can use the following parameters in this message:

Parameter Description
%%value%% The current (invalid) value

normalize Boolean

Normalizer string before validate (trim, etc.).

Default: false.

version String

This determines exactly how the IP address is validated and can take one of a variety of different values.

Default: "4".

All ranges
  • 4 - Validates for IPv4 addresses
  • 6 - Validates for IPv6 addresses
  • all - Validates all IP formats
No private ranges
  • 4_no_priv - Validates for IPv4 but without private IP ranges
  • 6_no_priv - Validates for IPv6 but without private IP ranges
  • all_no_priv - Validates for all IP formats but without private IP ranges
No reserved ranges
  • 4_no_res - Validates for IPv4 but without reserved IP ranges
  • 6_no_res - Validates for IPv6 but without reserved IP ranges
  • all_no_res - Validates for all IP formats but without reserved IP ranges
Only public ranges
  • 4_public - Validates for IPv4 but without private and reserved ranges
  • 6_public - Validates for IPv6 but without private and reserved ranges
  • all_public - Validates for all IP formats but without private and reserved ranges

Methods

errors ()sogv.Error inherited

Return error errors

Returns:
Type Description
sogv.Error Error messages

isValid ()Boolean inherited overrides

Check if data valid.

Returns:
Type Description
Boolean Validation status