I need to replace some characters with others in an input on the fly and I thought that with javascript I can solve it.
The issue is as follows: I have an input that reads EAN13 codes and I have it prepared so that when inserting the numbers it validates it.
The fact is that now there is a barcode reading gun and when clicking on the input and scanning a code instead of writing numbers it writes the symbols that are in those numbers for example in the 6 he puts an & in the 5 a % and so with everyone. So I need when writing the javascript symbols to change them to the number assigned to that key in order to validate it and for us humans to understand it.
Can this be done with javascript? what would be the syntax?
The best way to avoid String.replace and regular expressions would be to create a manual dictionary and depending on the character, load the letter corresponding to the key in the dictionary.
Example (also in jsbin ):
I leave an example with replace() as an alternative to the previous answer
From what I understand, the barcode gun instead of placing the numeric digits that are on the alphanumeric keyboard from 0 to 9, it places the signs that are on those keys.
If you are correct, here is an example of one
input
that, when writing the signs that are on the keys from 0 to 9, replaces them with their numeric contract (that is, it ignores the Shift key :On the other hand, I suggest you review the manual of said gun because surely said functionality must be able to be configured, I hope this helps you, Greetings! ;))..