Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Javascript .test regex not work in some cases

$
0
0

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.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>