Wednesday 2 December 2015

Disable first character in textbox Using Jquery

<input type="text" id="nameId" value="Given Name"/>


<script type="text/javascript">
    $(function(){
       $("#nameId").on("keydown", function(e) {
    if (($(this).get(0).selectionStart == 0 && (e.keyCode < 35 || e.keyCode > 40))
        || ($(this).get(0).selectionStart == 1 && e.keyCode == 8)) {
        return false;
}
});

$("#nameId").bind("contextmenu", function(e) {
    e.preventDefault();
});
    });
</script>

No comments: