I have these two functions. Idea is I need to display alert when user type non latin characters
$("#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);}
For some reason checkDoesTextIncludesUnexpectedCharacters
return true all of the time.Even when console.log(text);
print text. For example 'Test' text return false
What is strange if I Hardcode text when call function, for exampleif (!unsupportedCharsAlertShown && checkDoesTextIncludesUnexpectedCharacters('Test'))
checkDoesTextIncludesUnexpectedCharacters
work and return false.