Guys and gals i have this piece of JavaScript code that only allows for numbers and one decimal period. The problem i\'m having is that when i tab over to my textbox contro
If you can't use an already stable and well-know library, you can try something like this:
document.write('');
function run(field) {
setTimeout(function() {
var regex = /\d*\.?\d?/g;
field.value = regex.exec(field.value);
}, 0);
}
I know it doesn't prevent the wrong char to appear, but it works.
PS: that setTimeout(..., 0) is a trick to execute the function after the value of the field has already been modified.