Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
99
rated 0 times [  101] [ 2]  / answers: 1 / hits: 23260  / 11 Years ago, fri, march 15, 2013, 12:00:00

I have a situation where I need to restrict users from entering space in beginning of a TextBox.
I am able to restrict space entry in TextBox. But not having any clues about not allowing at first position.



I am looking for a solution using JavaScript or jQuery. Any help would be appreciated.


More From » jquery

 Answers
16

keypress event solution:



$(input).on(keypress, function(e) {
if (e.which === 32 && !this.value.length)
e.preventDefault();
});


DEMO: http://jsfiddle.net/pdzBy/


[#79573] Thursday, March 14, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shamya

Total Points: 38
Total Questions: 101
Total Answers: 96

Location: Thailand
Member since Thu, Apr 22, 2021
3 Years ago
;