Код: Выделить всё
Type your message here...
Код: Выделить всё
$("#card-personalize-text").on('change keyup', function () {
if (!unsupportedCharsAlertShown && checkDoesTextIncludesUnexpectedCharacters($(this).text())) {
alert(unsupportedCharsMessage);
unsupportedCharsAlertShown = true;
}
});
Код: Выделить всё
function checkDoesTextIncludesUnexpectedCharacters(text) {
console.log(text);
console.log(!/^[A-Za-z0-9\/?!.:(){}]*$/.test(text));
return !/^[A-Za-z0-9\/?!.:(){}]*$/.test(text);
}
Например, когда вводишь текст «Тест» в #card-personalize-text
1st вывод журнала консоли 'Text'
2-й вывод true
Что странно, если я жестко кодирую текст при вызове функции, например
Код: Выделить всё
if (!unsupportedCharsAlertShown && checkDoesTextIncludesUnexpectedCharacters('Test'))Код: Выделить всё
checkDoesTextIncludesUnexpectedCharactersФрагмент стека:
Код: Выделить всё
let unsupportedCharsAlertShown = false;
const unsupportedCharsMessage = "Unsupported character!";
$("#card-personalize-text").on('change keyup', function () {
if (!unsupportedCharsAlertShown && checkDoesTextIncludesUnexpectedCharacters($(this).text())) {
alert(unsupportedCharsMessage);
unsupportedCharsAlertShown = true;
}
});
function checkDoesTextIncludesUnexpectedCharacters(text) {
console.log(text);
console.log(!/^[A-Za-z0-9\/?!.:(){}]*$/.test(text));
return !/^[A-Za-z0-9\/?!.:(){}]*$/.test(text);
}Код: Выделить всё
Type your message here...
Подробнее здесь: https://stackoverflow.com/questions/783 ... some-cases
Мобильная версия