You can replace ',' with '.' better inside a keyup event handler with the following
$(this).val($(this).val().replace(/,/,'.'));
So you can use the following dataEvents
dataEvents: [ { type: 'keyup', fn: function(e) { var oldVal = $(this).val(); var newVal = oldVal.replace(/,/,'.'); if (oldVal !== newVal) { $(this).val(newVal); } } }, { type: 'keypress', fn: function(e) { var key = e.charCode || e.keyCode; // to support all browsers if((key < 48 || key > 57) && // if non digit key !== 46 && key !== 44 && key !== 8 && // and not . or , or backspace key !== 37 && key !== 39) { // arrow left and arrow right return false; } } } ]
In the next demo you can see the results live. The only drawback that I see in this example is the following: if you try to enter a comma in the middle of the text , the cursor position (carriage) will be changed until the end of the input after replacing the comma. This is probably not a real problem in your case. That you want to keep the cursor position, you should probably do this document.selection for IE or .selectionStart and .selectionEnd for Firefox.
UPDATED . I fixed the problem using e.keyCode inside the keypress event in Firefox. I follow the information from here and now use e.charCode || e.keyCode e.charCode || e.keyCode instead of e.keyCode . The above code and demo are fixed.
Oleg
source share