javascript - Unable to add spaces to input text -
hi have following code, know how can modify user can add spaces?
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
Post a Comment