LuCI.validation.ValidatorFactory. types

Collection of type handlers. Each function consumes this.value and returns this.assert to report errors.

All functions return the result of assert().

Methods

and() → {boolean}

Logical AND && to build more complex expressions. Enforces all types on the input string.

See also or

Parameters:
NameTypeDescription
...argsstring

other types validation functions

Returns:
Type: 
boolean

cidr(negativeopt) → {boolean}

Assert a IPv4/6 CIDR.

Parameters:
NameTypeAttributesDescription
negativeboolean<optional>

allow netmask forms with /-... to mark negation of the range.

Returns:
Type: 
boolean

cidr4(negativeopt) → {boolean}

Assert a IPv4 CIDR.

Parameters:
NameTypeAttributesDescription
negativeboolean<optional>

allow netmask forms with /-.... E.g. 192.0.2.1/-24 to mark negation of the range.

Returns:
Type: 
boolean

cidr6(negativeopt) → {boolean}

Assert a IPv6 CIDR.

Parameters:
NameTypeAttributesDescription
negativeboolean<optional>

allow netmask forms with /-.... E.g. 2001:db8:dead:beef::/-64 to mark negation of the range.

Returns:
Type: 
boolean

dateyyyymmdd() → {boolean}

Assert a string of the form YYYY-MM-DD.

Returns:
Type: 
boolean

device() → {boolean}

Assert a device string. This is a hold-over from Lua to maintain compatibility and is a stub function.

Returns:

Always returns true.

Type: 
boolean

directory() → {boolean}

Assert a directory string. This is a hold-over from Lua to maintain compatibility and is a stub function.

Returns:

Always returns true.

Type: 
boolean

file() → {boolean}

Assert a file string. This is a hold-over from Lua to maintain compatibility and is a stub function.

Returns:

Always returns true.

Type: 
boolean

float() → {boolean}

Assert a signed float value (+/-).

Returns:
Type: 
boolean

hexstring() → {boolean}

Assert a hexadecimal string.

Returns:
Type: 
boolean
Example
FFFE // valid
FFF  // invalid

host(ipv4onlyopt) → {boolean}

Assert a valid hostname or IP address.

Parameters:
NameTypeAttributesDescription
ipv4onlyboolean<optional>

enforce IPv4 IPs only.

Returns:
Type: 
boolean

hostname(strictopt) → {boolean}

Validate hostname according to common rules.

Parameters:
NameTypeAttributesDescription
strictboolean<optional>

reject leading underscores.

Returns:
Type: 
boolean

hostport(ipv4onlyopt) → {boolean}

Assert a valid host:port.

Parameters:
NameTypeAttributesDescription
ipv4onlyboolean<optional>

restrict to IPv4 IPs only.

Returns:
Type: 
boolean

integer() → {boolean}

Assert a signed integer value (+/-).

Returns:
Type: 
boolean

ip4addr(nomaskopt) → {boolean}

Assert an IPv4 address.

Parameters:
NameTypeAttributesDescription
nomaskstring<optional>

reject a /x netmask.

Returns:
Type: 
boolean

ip4addrport(ipv4onlyopt) → {boolean}

Assert a valid IPv4 address:port. E.g. 192.0.2.10:80

Parameters:
NameTypeAttributesDescription
ipv4onlyboolean<optional>

restrict to IPv4 IPs only.

Returns:
Type: 
boolean

ip4prefix() → {boolean}

Assert an IPv4 prefix.

Returns:
Type: 
boolean

ip6addr(nomaskopt) → {boolean}

Assert an IPv6 address.

Parameters:
NameTypeAttributesDescription
nomaskstring<optional>

reject a /x netmask.

Returns:
Type: 
boolean

ip6hostid() → {boolean}

Assert a IPv6 host ID.

Returns:
Type: 
boolean

ip6ll(nomaskopt) → {boolean}

Assert an IPv6 Link Local address.

Parameters:
NameTypeAttributesDescription
nomaskstring<optional>

reject a /x netmask.

Returns:
Type: 
boolean

ip6prefix() → {boolean}

Assert an IPv6 prefix.

Returns:
Type: 
boolean

ip6ula(nomaskopt) → {boolean}

Assert an IPv6 UL address.

Parameters:
NameTypeAttributesDescription
nomaskstring<optional>

reject a /x netmask.

Returns:
Type: 
boolean

ipaddr(nomaskopt) → {boolean}

Assert an IPv4/6 address.

Parameters:
NameTypeAttributesDescription
nomaskstring<optional>

reject a /x netmask.

Returns:
Type: 
boolean

ipaddrport(bracketopt) → {boolean}

Assert a valid IPv4/6 address:port. E.g. 192.0.2.10:80 or [2001:db8:f00d:cafe::1]:8080

Parameters:
NameTypeAttributesDescription
bracketboolean<optional>

mandate bracketed [IPv6] URI form IPs.

Returns:
Type: 
boolean

ipmask(negativeopt) → {boolean}

Assert an IPv4/6 network in address/netmask (CIDR or mask) notation.

Parameters:
NameTypeAttributesDescription
negativeboolean<optional>

allow netmask forms with /-... to mark negation of the range.

Returns:
Type: 
boolean

ipmask4(negativeopt) → {boolean}

Assert an IPv4 network in address/netmask (CIDR or mask) notation.

Parameters:
NameTypeAttributesDescription
negativeboolean<optional>

allow netmask forms with /-... to mark negation of the range.

Returns:
Type: 
boolean

ipmask6(negativeopt) → {boolean}

Assert an IPv6 network in address/netmask (CIDR or mask) notation.

Parameters:
NameTypeAttributesDescription
negativeboolean<optional>

allow netmask forms with /-... to mark negation of the range.

Returns:
Type: 
boolean

ipnet4() → {boolean}

Assert an IPv4 network in address/netmask notation. E.g. 192.0.2.1/255.255.255.0

Returns:
Type: 
boolean

ipnet6() → {boolean}

Assert an IPv6 network in address/netmask notation. E.g. 2001:db8:dead:beef::0001/ffff:ffff:ffff:ffff::

Returns:
Type: 
boolean

iprange() → {boolean}

Assert a valid IPv4/6 address range.

Returns:
Type: 
boolean

iprange4() → {boolean}

Assert a valid IPv4 address range. E.g. 192.0.2.1-192.0.2.254.

Returns:
Type: 
boolean

iprange6() → {boolean}

Assert a valid IPv6 address range. E.g. 2001:db8:0f00:0000::-2001:db8:0f00:0000:ffff:ffff:ffff:ffff.

Returns:
Type: 
boolean

length(len) → {boolean}

Assert a string of bytelen length len characters.

Parameters:
NameTypeDescription
lenstring

set the length.

Returns:
Type: 
boolean

list(subvalidator, subargs) → {boolean}

Assert a list of a type.

Parameters:
NameTypeDescription
subvalidatorstring

other types validation functions

subargsstring

arguments to pass to the subvalidator

Returns:
Type: 
boolean
Example
list(string)

macaddr(multicastopt) → {boolean}

Assert a valid (multicast) MAC address.

Parameters:
NameTypeAttributesDescription
multicastboolean<optional>

enforce a multicast MAC address.

Returns:
Type: 
boolean

max(max) → {boolean}

Assert a decimal value lesser or equal to max.

Parameters:
NameTypeDescription
maxstring

set end of range.

Returns:
Type: 
boolean

maxlength(max) → {boolean}

Assert a value of bytelen with at most max characters.

Parameters:
NameTypeDescription
maxstring

set the max length.

Returns:
Type: 
boolean

min(min) → {boolean}

Assert a decimal value greater or equal to min.

Parameters:
NameTypeDescription
minstring

set start of range.

Returns:
Type: 
boolean

minlength(min) → {boolean}

Assert a value of bytelen with at least min characters.

Parameters:
NameTypeDescription
minstring

set the min length.

Returns:
Type: 
boolean

neg() → {boolean}

Assert any type, optionally preceded by !.

Example:list(neg(macaddr)) mandates a list of MAC values, which may also be prefixed with a single !; the MAC strings are validated after ! are removed from all entries.

01:02:03:04:05:06
!01:02:03:04:05:07
01:02:03:04:05:08
Parameters:
NameTypeDescription
...argsstring

other types validation functions

Returns:
Type: 
boolean

netdevname() → {boolean}

Assert a valid network device name between 1 and 15 characters not containing ":", "/", "%" or spaces.

Returns:
Type: 
boolean

network() → {boolean}

Assert a valid UCI identifier, hostname or IP address range.

Returns:
Type: 
boolean

or() → {boolean}

Logical OR || to build a more complex expression. Allows multiple types within a single field.

See also and

Parameters:
NameTypeDescription
...argsstring

other types validation functions

Returns:
Type: 
boolean

phonedigit() → {boolean}

Assert a valid phone number dial string: [0-9*#!.]+.

Returns:
Type: 
boolean

port() → {boolean}

Assert a valid port value where 0 <= port <= 65535.

Returns:
Type: 
boolean

portrange() → {boolean}

Assert a valid port or port range (port1-port2) where both ports are positive integers, port1 <= port2 and port2 <= 65535 (2^16 - 1).

Returns:
Type: 
boolean

range(min, max) → {boolean}

Assert a decimal value between min and max.

Parameters:
NameTypeDescription
minstring

set start of range.

maxstring

set end of range.

Returns:
Type: 
boolean
Example
range(-253, 253) // assert a value between -253 and +253

'range(%u,%u)'.format(min_vid, feat.vid_option ? 4094 : num_vlans - 1);
// assert values calculated at runtime for VLAN IDs.

rangelength(min, max) → {boolean}

Assert a string value of bytelen length between min and max characters.

Parameters:
NameTypeDescription
minstring

set the min length.

maxstring

set the max length.

Returns:
Type: 
boolean

sep(str) → {boolean}

Define a string separator sep for use in tuple.

Parameters:
NameTypeDescription
strstring

define the separator string

Returns:
Type: 
boolean

string(paramopt) → {boolean}

Assert a string type, optionally matching param.

Parameters:
NameTypeAttributesDescription
paramstring<optional>

define an optional exact string

Returns:
Type: 
boolean

timehhmmss() → {boolean}

Assert a string of the form HH:MM:SS.

Returns:
Type: 
boolean

tuple(…types, sep()opt) → {boolean}

Tuple validator: accepts 1-N tokens separated by a given separator sep (whitespace by default if sep is omitted) which will be validated against the 1-N types.

This differs from and by first splitting the input and applying each validator function sequentially on the resulting array of the split string, whereby the first type applies to the first value element, the second to the second, and so on, to define a concrete order.

sep can appear at any position in the list.

Parameters:
NameTypeAttributesDescription
typesfunction<repeatable>

types validation functions

sep()string<optional>

function to define split separator string.

Returns:
Type: 
boolean
Example
tuple(ipaddr,port) // "192.0.2.1 88"

tuple(host,port,sep(',')) // "taurus,8000"

tuple(port,port,port,sep('-')) // "33-45-78"

ucifw4zonename() → {boolean}

Assert a valid fw4 zone name UCI identifier: [a-zA-Z_][a-zA-Z0-9_]+

Returns:
Type: 
boolean

uciname() → {boolean}

Assert a valid UCI identifier: [a-zA-Z0-9_]+.

Returns:
Type: 
boolean

ufloat() → {boolean}

Assert an unsigned float value (+).

Returns:
Type: 
boolean

uinteger() → {boolean}

Assert an unsigned integer value (+).

Returns:
Type: 
boolean

unique(subvalidator, subargs) → {boolean}

Assert unique values among lists.

Parameters:
NameTypeDescription
subvalidatorstring

other types validation functions

subargsstring

arguments to subvalidators

Returns:
Type: 
boolean

wepkey() → {boolean}

Assert a valid (hexadecimal) WEP key.

Returns:
Type: 
boolean

wpakey() → {boolean}

Assert a valid (hexadecimal) WPA key of 8 <= length <= 63, or hex if length == 64.

Returns:
Type: 
boolean