Skip to content

inArray rule (v3)

Validate if user input is in given array. Similar to contains, but with an array.

Since
2.2.0
Signature
inArray(input, string)
Options
1

Usage

inArray usage
bootstrapValidate('#input', 'inArray:(ABC, DEF, GHI):Your input must be any of (ABC, DEF, GHI)')

Options

Name Description Example
string string: Array String (abc, def, ghi) (ABC, DEF, GHI)

Live Example

Checking...

Source

inArray source
/**
* @since 2.2.0
* @example (ABC, DEF, GHI)
* @param string string: Array String (abc, def, ghi)
* @error Your input must be any of (ABC, DEF, GHI)
* @description Validate if user input is in given array. Similar to contains, but with an array.
*/
export default function inArray(input: RuleInput, string: RuleOption) {
const { value } = input;
const array = split(String(string).replace("(", "").replace(")", "").trim(), ",");
return array.includes(value);
}