-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Datatypes
Datatypes are functions to dynamically validate the user input on the client side using Javascript.
A datatype is defined as a
- Standard validation:
#!lua cbi_element.datatype = "type"
- Validation with arguments:
#!lua cbi_element.datatype = "type(123, 'arg2')"
- Combination of a meta type and mixed types and strings:
#!lua cbi_element.datatype = [[ metatype(type(123, "arg2"), type, "string", 456) ]]
Makes it possible to validate against one or more datatypes in the same field.
Example usage:
#!lua cbi_element.datatype = [[ and(max(2048), uinteger) ]]
- Would allow using integers from 0 to 2048, no decimals.
Makes it possible to use different datatypes in the same field.
Example usage:
#!lua cbi_element.datatype = [[ or(min(30), -1, "infinity") ]]
- Would allow using -1, a positive number except from 0 to 29 and allow the term infinity to be used.
Allow using an exclamation mark in front of the value.
Example usage:
#!lua cbi_element.datatype = "neg(ipaddr)"
Allow the usage of a space separated multi-value.
Verify if the value is either 1, yes, on, true or 0, no, off, false.
Example: on
Verify if the value is a positive (unsigned) number and doesn't contain decimals.
Example: 2900
Verify if the value is a number doesn't contain decimals.
Example: -1090
Verify if the value is a positive number.
Example: 87.5
Verify if the value is a number.
Example: -192.34
Verify if the value is an IP address, either IPv4 or IPv6.
Verify if the value is an IPv4 address.
Example: 198.51.100.49
Verify if the value is a ip4prefix between 0 and 32.
Example: 24
Verify if the value is an IPv6 address.
Example: 2001:db8:1200::ab:45ff:fe12:3456
Verify if the value is a ip6prefix between 0 and 128.
Example: 64
Verify if the value is a port between 0 and 65535.
Example: 8080
Verify if the value contains one or more port separated by a dash.
Example: 67-69
Verify if the value is a valid MAC address separated by colons. The address may contain uppercase and lowercase hexadecimal characters.
Examples: 62:11:22:aa:bb:cc
Verify if the value is a valid DNS domain name or hostname. The hostname can contain uppercase and lowercase alphanumerical characters, underscore, dash and dots. Hostname cannot start with a dash or end with a dot.
Example: this_IS-a.valid.host.name
Verify if the value is a valid hostname or IP address.
Example: openwrt.domain.local
Same as host but also allows UCI network names found in the Network, Interfaces page.
Example: lan
Verify if the value is a valid WPA pre-shared key, from 8 to 63 characters or a valid WPA key containing exactly 64 hexadecimal characters.
Example: *This is+a,valid WPA key 123%
Verify if the value is a valid 40 bits or 104 bit WEP key or string. If the WEP key is defined as a string, it must start with s: and contain either 5 or 13 characters. If the key is defined as hexadecimal, it must contain exactly 10 or 26 hexadecimal characters.
Example: 123abcd890
Does not validate anything.
Tests on the server side whether the value is a path pointing to a directory or a path pointing to a symlink of a directory.
Example: /tmp
Tests on the server side whether the value is a path pointing to a directory or a path pointing to a symlink of a directory.
Example: /tmp/resolv.conf
Tests on the server side whether the value is a path pointing to a device or a path pointing to a symlink of a device.
Example: /dev/null
Verify if the value is a valid UCI name.
Example: lan
Verify if the value is a valid number between min and max.
Example: 100
Verify if the value is a valid number above or equal to min.
Example: 152
Verify if the value is a valid number below or equal to max.
Example: -80
Verify if the value fits in length between min characters and max characters.
Example: This is a test string
Verify if the value has at least min characters or more.
Example: 1200
Verify if the value has at most max characters or less.
Example: 500
Verify if the value qualifies as a phone number containing digits from 0 to 9, star, or pound.
Example: 18005555555##123*