100
rated 0 times
[
106]
[
6]
/ answers: 1 / hits: 71389
/ 11 Years ago, sun, march 10, 2013, 12:00:00
I have this JS function that prevents user from typing characters
<script type=text/javascript>
function validate(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();
}
}
</script>
<span>Radio Receive:</span>
<input name=ReceiveNo type=text class=txtbox onkeypress='validate(event)' maxlength=11 value=${cpCon.receiveNo} required tabindex=34 />
But I noticed that when the user tried to paste a word from this textbox, the text can be entered. How can I prevent this without disabling the paste?
More From » html