Format rules LIVR 2.5
Format rules check that a value is an identifier, a network address, an encoding or another common format. They check the string form of a primitive value, and return it. A boolean gives the error code of the rule (true is not a hostname, although 'true' is), and an object or a list gives FORMAT_ERROR. A number is checked as its string form: 123 passes hex and gives '123'.
Hex digits are 0-9a-fA-F. All hex comparisons are case-insensitive, and the case of the input is kept in the output. A rule without arguments that is given arguments, or an unknown argument value, is a schema error.
These rules were added in LIVR 2.5.
uuid2.5Checks that the value is a UUID (RFC 9562), of any version or of the given versions.'uuid', { uuid: 'v4' }WRONG_UUIDip2.5Checks that the value is an IPv4 or an IPv6 address.'ip', { ip: 'v4' }WRONG_IPcidr2.5Checks that the value is an IP address with a prefix length, for example 192.0.2.0/24.'cidr', { cidr: 'v4' }WRONG_CIDRhostname2.5Checks that the value is a hostname (RFC 1123), for example api.example.com or localhost.'hostname'WRONG_HOSTNAMEbase642.5Checks that the value is a Base64 string (RFC 4648).'base64'FORMAT_ERRORhex2.5Checks that the value is a string of hex digits 0-9a-fA-F, without the 0x prefix.'hex'WRONG_HEXdigest2.5Checks that the value is a hex digest of one of the given hash algorithms.{ digest: 'sha256' }WRONG_DIGESTmongo_id2.5Checks that the value is a BSON ObjectId: 24 hex digits.'mongo_id'WRONG_MONGO_IDhex_color2.5Checks that the value is a hex color: # and 3, 4, 6 or 8 hex digits, for example #f80 or #FF8800.'hex_color'WRONG_HEX_COLORmac2.5Checks that the value is a MAC address: six pairs of hex digits separated by : or by -. { mac: 64 } checks a 64-bit EUI-64 identifier: eight pairs.'mac', { mac: 64 }WRONG_MACe1642.5Checks that the value is a phone number in the E.164 format: +, then 7–15 digits, the first of which is not 0.'e164'FORMAT_ERRORsemver2.5Checks that the value is a semantic version, for example 1.2.3 or 2.0.0-rc.1+build.5.'semver'WRONG_SEMVERjwt2.5Checks that the value has the structure of a JSON Web Token: header.payload.signature in base64url, the JWS compact serialization (RFC 7515, section 7.1). The token is not decoded or verified.'jwt'WRONG_JWT