javascript - Unable to add spaces to input text -


hi have following code, know how can modify user can add spaces?

jsfiddle

i used code , modified here:

$('#text').keyup(function(e, w) {             $("#prev").html($(this).val());              var txtwidth = $( "#text-preview" ).width();             $( "#textwidth" ).text( "approx. width: " + txtwidth + " px." );         }).keypress(function(e) {             return /[a-z0-9.-]/i.test(string.fromcharcode(e.which));         }); 

html:

                          <!--display user input-->                           <span id="text-preview"><p id="prev" class="form_result"></p></span>                       <!--display width-->                       <p id="textwidth"></p>                           <label class="sign-text">enter text                             <input type="text" name="text" id="text" class="form-control enter-text-field validation-passed" value="enter text">                           </label> 

$('#text').keyup(function(e, w) {             $("#prev").html($(this).val());              var txtwidth = $( "#text-preview" ).width();             $( "#textwidth" ).text( "approx. width: " + txtwidth + " px." );         }).keypress(function(e) {             return /[a-z0-9.-\s]/i.test(string.fromcharcode(e.which));         }); 

the regex in keypress function needs \s support space characters.


Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -