LuCI.validation. ValidatorFactory

Factory to create Validator instances and compile validation expressions.

Namespaces

types

Methods

compile(code) → {Array}

Compile a validator expression string into an internal stack representation.

Parameters:
NameTypeDescription
codestring

Validator expression string (e.g. or(ipaddr,port)).

Returns:

Compiled token stack used by validators.

Type: 
Array

create(field, type, optional, vfunc) → {Validator}

Compile a validator expression string into an internal stack representation.

Parameters:
NameTypeDescription
fieldstring

field name

typestring

validator type

optionalboolean

whether the field is optional

vfuncstring

a validator function

Returns:

Compiled token stack used by validators.

Type: 
Validator

parseDecimal(x) → {number}

Parse a decimal number string. Returns NaN when not a valid number.

Parameters:
NameTypeDescription
xstring
Returns:

Decimal number or NaN

Type: 
number

parseIPv4(x) → {Array.<number>|null}

Parse IPv4 address into an array of 4 octets or return null on failure.

Parameters:
NameTypeDescription
xstring

IPv4 address string

Returns:

Array of 4 octets or null.

Type: 
Array.<number> | null

parseIPv6(x) → {Array.<number>|null}

Parse IPv6 address into an array of 8 16-bit words or return null on failure. Supports IPv4-embedded IPv6 (::ffff:a.b.c.d) and zero-compression.

Parameters:
NameTypeDescription
xstring

IPv6 address string

Returns:

Array of 8 16-bit words or null.

Type: 
Array.<number> | null

parseInteger(x) → {number}

Parse an integer string. Returns NaN when not a valid integer.

Parameters:
NameTypeDescription
xstring
Returns:

Integer or NaN

Type: 
number