Javascript examples for DOM HTML Element:Input Text
Validate input text box by key code and selection start
<html> <head> <script> function ValidateInput(ctrl) { console.log(event.keyCode); console.log(ctrl.selectionStart); if (event.keyCode == 8 ||event.keyCode == 46) { if (ctrl.selectionStart <= 4) return false;/*from w w w. jav a 2s .co m*/ } return true; } </script> </head> <body> <input type="text" id="Name" name="Name" value="1234" onkeydown="return ValidateInput(this);"> </body> </html>