1

i written a java script which allows only numbers,comma,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)

1 Answer 1

7

You 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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.