Class: UuidValidator

sogv.UuidValidator

Validates that a value is a valid Universally unique identifier (UUID) per RFC 4122.

By default, this will validate the format according to the RFC's guidelines, but this can be relaxed to accept non-standard UUIDs that other systems (like PostgreSQL) accept.

UUID versions can also be restricted using a whitelist.

new sogv.UuidValidator (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: ['uuid'].

options Object The description of the required options.
Example
var validator = new sogv.UuidValidator(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 UUID.

Default: "This is not a valid UUID."

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.

strict Boolean

If this option is set to true the constraint will check if the UUID is formatted per the RFC's input format rules: 216fff40-98d9-11e3-a5e2-0800200c9a66.

Default: true.

Setting this to false will allow alternate input formats like:

  • 216f-ff40-98d9-11e3-a5e2-0800-200c-9a66
  • {216fff40-98d9-11e3-a5e2-0800200c9a66}
  • 216fff4098d911e3a5e20800200c9a66

versions Array

This option can be used to only allow specific UUID versions.

Valid versions are 1 - 5.

Default: [1,2,3,4,5].

The following PHP constants can also be used:

  • 1 - Date-Time and MAC address
  • 2 - Date-Time and MAC address, DCE security version
  • 3 - Namespace name-based (MD5)
  • 4 - Random
  • 5 - Namespace name-based (SHA-1)

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