Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to disable space in input type="text"

Can someone show me an example of how i can edit the below code to disable or remove space when typing in input type="text field.

<input type="text" id="username" name="username" class="{{ \App\getAllClasses()['text'] }}" placeholder="Username">

I tried to to find a similar script but to no avail.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can disable the spaces in the input field like this:

<input
  type="text"
  id="username"
  name="username"
  class="{{ \App\getAllClasses()['text'] }}"
  placeholder="Username"
  onkeypress="return event.charCode != 32"
/>

The onkeypress event handler checks the ASCII code of the character being typed, and if it’s 32 (the ASCII code for the space character), it returns false, which means the space won’t be entered into the input field.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading