我写了一个javascript函数,只允许这样的数字,逗号,点
function isNumber(evt) { var theEvent = evt || window.event; var key = theEvent.keyCode || theEvent.which; key = String.fromCharCode(key); var regex = /^[0-9.,]+$/; if (!regex.test(key)) { theEvent.returnValue = false; if (theEvent.preventDefault) theEvent.preventDefault(); } }
但如果我想删除任何数字形式的文本框..退格无法正常工作.然后我将正则表达式代码更改为" var regex = /^[0-9.,BS]+$/;
"
仍然我无法在textbox中使用退格键.即使我在文本框上使用左右键我是做错了吗?任何人都可以帮助...谢谢.(当我在正则表达式中使用"BS"而不是退格时,它允许文本框中的"B","S"字符..)