CURRENT PROJECTS
loading
/* onKeyPress validation function */ function validVal(event, keyRE) { if ( ( typeof(event.keyCode) != 'undefined' && event.keyCode > 0 && String.fromCharCode(event.keyCode).search(keyRE) != (-1) ) || ( typeof(event.charCode) != 'undefined' && event.charCode > 0 && String.fromCharCode(event.charCode).search(keyRE) != (-1) ) || ( typeof(event.charCode) != 'undefined' && event.charCode != event.keyCode && typeof(event.keyCode) != 'undefined' && event.keyCode.toString().search(/^(8|9|13|45|46|35|36|37|39)$/) != (-1) ) || ( typeof(event.charCode) != 'undefined' && event.charCode == event.keyCode && typeof(event.keyCode) != 'undefined' && event.keyCode.toString().search(/^(8|9|13)$/) != (-1) ) ) { return true; } else { return false; } }
<head> <script> function reKeyPress(event, keyRE) { var strr = ""; for(var i in event) { strr += "\n" + i + " - " + event[i]; } document.testing.eventBox.value = strr; document.testing.cCodePress.value = event.charCode; document.testing.kCodePress.value = event.keyCode; if ( ( typeof(event.keyCode) != 'undefined' && event.keyCode > 0 && String.fromCharCode(event.keyCode).search(keyRE) != (-1) ) || ( typeof(event.charCode) != 'undefined' && event.charCode > 0 && String.fromCharCode(event.charCode).search(keyRE) != (-1) ) || ( typeof(event.charCode) != 'undefined' && event.charCode != event.keyCode && typeof(event.keyCode) != 'undefined' && event.keyCode.toString().search(/^(8|9|13|45|46|35|36|37|39)$/) != (-1) ) || ( typeof(event.charCode) != 'undefined' && event.charCode == event.keyCode && typeof(event.keyCode) != 'undefined' && event.keyCode.toString().search(/^(8|9|13)$/) != (-1) ) ) { document.testing.pressValid.value = 'true'; return true; } else { document.testing.pressValid.value = 'false'; return false; } } function keyDownHandler(event) { document.testing.cCodeDown.value = event.charCode; document.testing.kCodeDown.value = event.keyCode; } </script> </head> <form name="testing"> north american 10digit phone number: <input type="text" size=10 maxlength=10 onKeyPress="return reKeyPress(event, /[0-9]/);" onKeyDown="keyDownHandler(event);"> <table> <tr> <td colspan=3> <textarea cols=50 rows=20 name="eventBox"></textarea> </td> </tr> <tr> <td></td> <td>onKeyPress</td> <td>onKeyDown</td> </tr> <tr> <td>charCode</td> <td><input type="text" size=10 maxlength=10 name="cCodePress" value=""></td> <td><input type="text" size=10 maxlength=10 name="cCodeDown" value=""></td> </tr> <tr> <td>keyCode</td> <td><input type="text" size=10 maxlength=10 name="kCodePress" value=""></td> <td><input type="text" size=10 maxlength=10 name="kCodeDown" value=""></td> </tr> <tr> <td>passes?</td> <td><input type="text" size=10 maxlength=10 name="pressValid" value=""></td> <td><input type="text" size=10 maxlength=10 name="downValid" value=""></td> </tr> </table> </form>