Ensure you don't share with yourself

This commit is contained in:
Max Berger
2026-03-11 21:44:04 +01:00
parent 434de50281
commit 93075cb20e
3 changed files with 56 additions and 2 deletions

View File

@@ -76,6 +76,27 @@ export function validate_non_empty(input, field_name) {
return field_name + " is empty";
};
}
/**
* Validates that the input is not empty and not equal to a target string.
* @param {HTMLInputElement} input
* @param {string} target
* @param {string} field_name
* @returns {function(): ?string}
*/
export function validate_not_empty_or_equals(input, target, field_name) {
return () => {
let value = input.value.trim();
if (!value) {
return field_name + " is empty";
}
if (value === target) {
return field_name + " cannot be " + target;
}
return null;
};
}
/**
* Validates that the input is a valid HREF.
* @param {HTMLInputElement} input