Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not allow a blank character / space in a input form [duplicate]

Is it possible to not allow a blank character / space in a input form like below?

<input type="text" value="" maxlength="30" name="email" class="formfield w0">
like image 247
user123 Avatar asked Sep 26 '13 09:09

user123


1 Answers

Check this Fiddle. Relevant code:

 $(function() {
        $('#input1').on('keypress', function(e) {
            if (e.which == 32){
                console.log('Space Detected');
                return false;
            }
        });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<input type="text" id="input1" />
like image 134
Raidri Avatar answered Oct 21 '22 03:10

Raidri