Good morning everybody!
I have a case, when I should prevent users to entering space as a first character on input field.
I have a demo here: http://jsbin.com/fo
You can do this by checking if key is space and selection start is 0 as below:
space
selection start
$(function() { $('body').on('keydown', '#test', function(e) { console.log(this.value); if (e.which === 32 && e.target.selectionStart === 0) { return false; } }); });
Demo Link