I am checking the date, and now I am doing that the user can only enter numbers , / and backspace , so now I want to add 2 more keys to my regular expression. I want to add delete and arrow keys so that the changes change in my regex. This is my code.
<input type="text" id="date" name="date" onkeypress="check(event,this);" />
this is me javascript code
<script type="text/javascript"> function check(evt, id) { var value = id.value; var theEvent = evt || window.event; var key = theEvent.keyCode || theEvent.which; key = String.fromCharCode( key ); var regex = /[0-9|\b|/]/; if( !regex.test(key)) { theEvent.returnValue = false; if(theEvent.preventDefault) theEvent.preventDefault(); } } </script>
Thanks, waiting for your help.
Azam alvi
source share