javascript - How to disable/remove only first space on input field? -


Good morning everyone!

I have a case when the first letter on the input field should prevent me from entering users space.

I have a demo here:

This only works when you hit spacebar for the first time. When you start typing the other characters and select the entire text in the input (ctrl + a) and then press the space bar, it adds the location at the beginning of the input field.

So, how the keypress / keydown if the first letter is a place, then return false and do not allow it to type the location as the first letter?

You can do that the key is space and selection Start is below:

  $ (function () {$ ('body'). ('Keydown', '#test', function (e) {console.log (This.value); if (e.which === 32 & amp; e.target .selectionStart === 0) {return false;}});});  


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -