Here I wan...">

How to check html text field to not allow special characters and space?

This is my html:

 <input type="text" name="folderName">

Here I want to check the value of the text field, not allowing you to enter special characters and space. But this should allow to emphasize.

How to check this text box?

+4
source share
5 answers

You can try using this function:

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript">
    function blockSpecialChar(e){
        var k;
        document.all ? k = e.keyCode : k = e.which;
        return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k >= 48 && k <= 57));
        }
    </script>
</head>
<body>
    <form id="frm" runat="server">
      <input type="text" name="folderName"  onkeypress="return blockSpecialChar(event)"/>
    </form>
</body>
</html>
+10
source

try it

$(document).ready(function () {
    $("#sub").click(function(){
var fn = $("#folderName").val();
    var regex = /^[0-9a-zA-Z\_]+$/
    alert(regex.test(fn));
});
});

Return false for special chars and spacesand refundtrue for underscore, digits and alphabets.

Fiddle: http://jsfiddle.net/7C5nP/

+4
source

jQuery + JQuery Validation Plugin. :

 <input type="text" data-validation="alphanumeric" data-validation-allowing="_">

jQuery: http://formvalidator.net/index.html

+1

:

<input class="form-control" onkeypress="return ((event.charCode > 64 && event.charCode < 91) || (event.charCode > 96 && event.charCode < 123) || event.charCode == 8 || event.charCode == 32 || (event.charCode >= 48 && event.charCode <= 57));" id="name" formControlName="name" type="text" autocomplete="off" value="">

.

+1

javascript, . . -: javascript-validation Javascript ( ).

0

Source: https://habr.com/ru/post/1548589/


All Articles