i written a java script which allows only numbers,ma,dot. i applied it on four text boxes. my issue is i have 10 text boxes which takes different types of data on which four of them i applied java script. i can use tab key on other text boxes but i am not able to use on java script applied text boxes to move courser. is there any change that i have to do in my script... Thanks.
Java Script:-
function isNumberCommaDot(evt) {
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
if (key.length == 0) return;
var regex = /^[0-9,\9\b]*\.?[0-9]*$/;
if (!regex.test(key)) {
theEvent.returnValue = false;
if (theEvent.preventDefault) theEvent.preventDefault();
}
}
i used \9 in regex but still its not accepting tab key.(9 is ASCII char. for TAB Key)
i written a java script which allows only numbers,ma,dot. i applied it on four text boxes. my issue is i have 10 text boxes which takes different types of data on which four of them i applied java script. i can use tab key on other text boxes but i am not able to use on java script applied text boxes to move courser. is there any change that i have to do in my script... Thanks.
Java Script:-
function isNumberCommaDot(evt) {
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
if (key.length == 0) return;
var regex = /^[0-9,\9\b]*\.?[0-9]*$/;
if (!regex.test(key)) {
theEvent.returnValue = false;
if (theEvent.preventDefault) theEvent.preventDefault();
}
}
i used \9 in regex but still its not accepting tab key.(9 is ASCII char. for TAB Key)
Share Improve this question edited Feb 6, 2014 at 1:49 vishnu reddy asked Feb 5, 2014 at 11:17 vishnu reddyvishnu reddy 1231 gold badge5 silver badges9 bronze badges1 Answer
Reset to default 7You can check whether it was a tab press earlier, and just skip processing
function isNumberCommaDot(evt) {
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
if (key === 9 ) { //TAB was pressed
return;
}
key = String.fromCharCode(key);
if (key.length == 0) return;
var regex = /^[0-9,\9\b]*\.?[0-9]*$/;
if (!regex.test(key)) {
theEvent.returnValue = false;
if (theEvent.preventDefault) theEvent.preventDefault();
}
}
You can find more info here