Skip to content

matches rule (v3)

Require the input value to match the given inputs value. Like bootstrapValidate's first Parameter, you can pass a selector or Element.

Since
1.1.0
Signature
matches(input, matchingInput)
Options
1

Usage

matches usage
bootstrapValidate('#input', 'matches:#passwordConfirm:Your passwords should match')

Options

Name Description Example
matchingInput string: The input element to match against #passwordConfirm

Live Example

Checking...

Source

matches source
/**
* @since 1.1.0
* @example #passwordConfirm
* @error Your passwords should match
* @param matchingInput string: The input element to match against
* @description Require the input value to match the given inputs value. Like bootstrapValidate's first Parameter, you can pass a selector or Element.
*/
export default function matches(input: RuleInput, matchingInput: string | number | RuleInput) {
let resolvedInput: RuleInput | null;
if (typeof matchingInput === "object" && typeof matchingInput.nodeType !== "undefined") {
resolvedInput = matchingInput;
} else {
resolvedInput = document.querySelector(String(matchingInput)) as RuleInput | null;
}
return Boolean(resolvedInput) && input.value === resolvedInput?.value;
}