What is the keyCode for “$”?

前端 未结 5 1926
萌比男神i
萌比男神i 2021-01-18 06:07

I am trying to disable all other characters from being entered in text input.

Since to get the $ you have to press the shift-key and the

5条回答
  •  天命终不由人
    2021-01-18 06:36

    Then DONT use this way to solve your problem: since you cannot predict that every keyboard-layout will always have $-sign entered as shift+4.
    You can still get keycode 4, and check if shift was pressed, but you could not be sure of this!!

    Thus it would be better to simply replace all illegal characters in your fields (before you submit the data). Think: str.replace()
    You could also check for your set of illegal characters on the onkeyup event of the input-box, effectively replacing all illegal characters as you type!
    Like: onkeyup="this.value.replace(/[your illegal characters]/gi, '')"
    That should do what you want.

    Please note: you should NEVER trust browser-input, and should still filter this input in your receiving script!!!

    Good Luck!!

提交回复
热议问题