Javascript function need allow numbers, dot and comma
问题 I need to create a function to allow numbers dot and comma. So anyone corrects the following function function on(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(); } } 回答1: Firstly your regex currently doesn't allow comma, which is your requirement. Secondly, you haven't used any