in source/console/src/util/CustomUtil.tsx [81:111]
export function validateGeneralInput(input: string, minLength: number, maxLength: number, allowedSpecialCharacters: string): boolean {
if (input === '' && minLength === 0) { return true; }
// Due to supporting multi-languages since v2.1, removed alphanumeric validation.
if (input.length > maxLength || input.length < minLength || input.trimLeft().trimRight() === '') {
return false;
}
let allowedSpecialCharactersCode: number[] = [];
for (let i = 0, length = allowedSpecialCharacters.length; i < length; i++) {
allowedSpecialCharactersCode.push(allowedSpecialCharacters.charCodeAt(i));
}
if (allowedSpecialCharactersCode.length > 0) {
for (let i = 0, length = input.length; i < length; i++) {
let ch = input.charCodeAt(i);
if (
(ch >= 32 && ch <= 47) || // [space] to "/"
(ch >= 58 && ch <= 64) || // ":" to "@"
(ch >= 91 && ch <= 96) || // "[" to "`"
(ch >= 123 && ch <= 127) // "{" to the end of ASCII
) {
if (!allowedSpecialCharactersCode.includes(ch)) {
return false;
}
}
}
}
return true;
}