0

I need to validate text input field for special characters. But it must accept letters from all languages available. What I have found across the web only checks for a-A0-9 alpha-numerical checks but letters like äöü are in this case considerate as special characters.
I can solve my problem with this regex check:

function onlyNumbersAndLettersAllowed(inputValue) {

    var regex = /[!~`@#$%^&*()_+=-?/><,.":;{}]/;

    if (inputValue.match(regex)) {
        return false;
    } else {
        return true;
    }

}

But there has to be some sophisticated solution for this. As I strive to become better developer, please show me how can I improve my code. Thanks.

user2450639
  • 196
  • 1
  • 14
  • 1
    please see first answer https://stackoverflow.com/questions/6381752/validating-users-utf-8-name-in-javascript – Viswanath Polaki Jun 04 '19 at 11:00
  • 2
    There are many 'special characters'. Are the ones in your regex the only ones you want to 'validate'? You must do this for a certain reason, if we know that reason we can probably give a better answer. – KIKO Software Jun 04 '19 at 11:02
  • 2
    @ViswanathPolaki - the "first answer" depends on your settings (active/oldest/votes)... use the `share` option against the specific answer you're referring to and use that URL instead – freefaller Jun 04 '19 at 11:05
  • Basically, all the special characters that can be added via keyboard . And I am not able to use plugins in this case :( – user2450639 Jun 04 '19 at 11:08
  • You're being too vague. There are hundreds (?) of special characters that can be entered with a keyboard. Can you not tell us the reason for doing this? For instance: "I need to create a Windows file name, and only certain characters are allowed", would already be a big help. – KIKO Software Jun 04 '19 at 11:17
  • @ViswanathPolaki If you believe the question is a duplicate, please do flag the question as such. – Heretic Monkey Jun 04 '19 at 21:18

0 Answers0