Reputation: 2281
I have html input fields and in mobile devices, the keyboard automatically adds spaces after sentence. This is problematic for a input of type "url". How do I disable it?
I tried the following and still adds a space after the period in the domain name.
<input id="url" type="url" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
Upvotes: 1
Views: 176
Reputation: 1128
Assuming you have your input stored in a variable and that you are interested in its value only when you do a submit, you can easily trim its value with
yourInput.trim();
this will remove all leading and trailing spaces, thus cleaning your input.
If you want to delete the spaces directly when typing, you can attach that code to the keyup event:
yourInput.addEventListener('keyup', e => e.currentTarget.value = e.currentTarget.value.trim());
Upvotes: 0