mv
mv reference and configuration shared across Fortified ID products.
Script extension for multi value validation and comparison.
All functions operating on multi values will convert supplied value(s) to multi value if not already (see mv.from(value))
In JavaScript multi values are represented as arrays.
mv.from
Section titled “mv.from”Converts a value to a multi value if not already.
Handles the following types of input values:
- arrays (returned as is)
- json arrays (parsed to array)
- single values of any types (added as first element to new array)
Syntax
Section titled “Syntax”mv.from(value)
Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
value | any | The value to convert to multi value |
Example(s)
Section titled “Example(s)”// Create multi value from single value stringmv.from('elem') // -> ['elem']
// Create multi value from json arraymv.from('["elem01", "elem02"]') // -> ['elem01', 'elem02']mv.length
Section titled “mv.length”Returns the length of the supplied multi value.
Syntax
Section titled “Syntax”mv.length(value)
Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
value | any | The multi value whose length is to be calculated and returned. |
Example(s)
Section titled “Example(s)”// Get multi value length of single value stringmv.length('elem') // -> 1
// Get multi value length of an arraymv.length(['elem01', 'elem02', 'elem03']) // -> 3
// Get multi value length of an json arraymv.length('["elem01", "elem02"]') // -> 2mv.contains
Section titled “mv.contains”Returns true if the supplied multi value contains the supplied expected value, possibly ignoring the case (if values are strings).
Note: This function works exactly like mv.containsAny but with support for only one expected value.
Syntax
Section titled “Syntax”mv.contains(value, expected[, ignoreCase])
Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
value | any | The multi value whose content is to be asserted. |
expected | any | Value expected to be contained in value |
ignoreCase | boolean | Flag turning on string case insensitivity (default: false) |
Example(s)
Section titled “Example(s)”mv.contains(['elem01', 'elem02', 'elem03'], 'elem02') // truemv.contains(['elem01', 'elem02', 'elem03'], 'elem04') // falsemv.contains(['elem01', 'elem02', 'elem03'], 'ELEM02', true) // true
mv.contains([7, 99, 845], 'unknown') // falsemv.contains([7, 99, 845], 7) // truemv.containsAny
Section titled “mv.containsAny”Returns true if the supplied multi value contains at least one of the supplied expected values, possibly ignoring the case (if values are strings).
Syntax
Section titled “Syntax”mv.containsAny(value, expected[, expected, ...][, ignoreCase])
Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
value | any | The multi value whose content is to be asserted. |
expected | any | One or more values expected to be contained in value |
ignoreCase | boolean | Flag turning on string case insensitivity (default: false) |
Example(s)
Section titled “Example(s)”mv.containsAny(['elem01', 'elem02', 'elem03'], 'elem02') // truemv.containsAny(['elem01', 'elem02', 'elem03'], 'elem04') // falsemv.containsAny(['elem01', 'elem02', 'elem03'], 'elem04', 'elem02') // truemv.containsAll
Section titled “mv.containsAll”Returns true if the supplied multi value contains all of the supplied expected values, possibly ignoring the case (if values are strings).
Syntax
Section titled “Syntax”mv.containsAll(value, expected[, expected, ...][, ignoreCase])
Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
value | any | The multi value whose content is to be asserted. |
expected | any | One or more values expected to be contained in value |
ignoreCase | boolean | Flag turning on string case insensitivity (default: false) |
Example(s)
Section titled “Example(s)”mv.containsAll(['elem01', 'elem02', 'elem03'], 'elem02') // truemv.containsAll(['elem01', 'elem02', 'elem03'], 'elem04') // falsemv.containsAll(['elem01', 'elem02', 'elem03'], 'elem04', 'elem02') // falsemv.containsAll(['elem01', 'elem02', 'elem03'], 'elem01', 'elem02') // truemv.matchAny
Section titled “mv.matchAny”Returns true if at least one value in the supplied multi value matches one or more of the supplied regex's.
Regex may be supplied as strings, regex-literals or RegExp objects.
Note: Case-insensitivity is controlled by regex flag ('i').
Syntax
Section titled “Syntax”mv.matchAny(value, regex [,regex, ...])
Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
value | any | The multi value whose content is to be matched. |
expected | any | One or more regex to match against value. |
Example(s)
Section titled “Example(s)”mv.matchAny(['elem01', 'elem02', 'elem03'], 'elem02', 'elem04') // truemv.matchAny(['elem01', 'elem02', 'elem03'], /elem02/, /elem04/) // truemv.matchAny(['elem01', 'elem02', 'elem03'], 'ELEM02') // falsemv.matchAny(['elem01', 'elem02', 'elem03'], /ELEM02/i) // truemv.matchAny(['elem01', 'elem02', 'elem03'], /^elem[0-9]{,2}$/) // truemv.equals
Section titled “mv.equals”Returns true if the supplied multi values has exactly same content.
Syntax
Section titled “Syntax”mv.equals(mv1, mv2)
Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
mv1 | any | The multi value whose content is to be matched. |
mv2 | any | One or more regex to match against value. |
Example(s)
Section titled “Example(s)”mv.equals(['elem01'], ['elem01']) // truemv.equals(['elem01'], ['elem02']) // false
mv.equals(['elem01', 'elem02'], ['elem01', 'elem02']) // true
mv.equals(['elem01', 'elem02'], ['elem01']) // falsemv.equals(['elem01', 'elem02'], ['elem02', 'elem01']) // falsemv.isEmpty
Section titled “mv.isEmpty”Returns true if the supplied multi value is not null/undefined and is empty.
Syntax
Section titled “Syntax”mv.isEmpty(value)
Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
value | any | The multi value to assert |
Example(s)
Section titled “Example(s)”mv.isEmpty([]) // true
mv.isEmpty(['elem01']) // falsemv.isEmpty(null) // falsemv.isNotEmpty
Section titled “mv.isNotEmpty”Returns true if the supplied multi value is not null/undefined and is not empty (has one or more elements).
Syntax
Section titled “Syntax”mv.isNotEmpty(value)
Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
value | any | The multi value to assert |
Example(s)
Section titled “Example(s)”mv.isNotEmpty(['elem01']) // true
mv.isNotEmpty([]) // falsemv.isNotEmpty(null) // falsemv.isNullOrEmpty
Section titled “mv.isNullOrEmpty”Returns true if the supplied multi value is null/undefined or is empty.
Syntax
Section titled “Syntax”mv.isNullOrEmpty(value)
Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
value | any | The multi value to assert |
Example(s)
Section titled “Example(s)”mv.isNullOrEmpty([]) // truemv.isNullOrEmpty(null) // true
mv.isNullOrEmpty(['elem01']) // falsemv.isNotNullOrEmpty
Section titled “mv.isNotNullOrEmpty”Returns true if the supplied multi value is not null/undefined and is not empty (has one or more element).
Syntax
Section titled “Syntax”mv.isNotNullOrEmpty(value)
Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
value | any | The multi value to assert |
Example(s)
Section titled “Example(s)”mv.isNotNullOrEmpty(['elem01']) // true
mv.isNotNullOrEmpty(null) // falsemv.isNotNullOrEmpty([]) // false