Paste in textarea without special chars

textarea special characters not allowed
how to restrict special characters in textbox using javascript
jquery on paste
restrict special characters in textbox jquery
how to restrict special characters in textbox using regular expression in javascript
javascript paste from clipboard to textarea
how to restrict special characters in textbox using php
javascript paste event get pasted text

I have some js function what don't allow few special characters, chars etc... Some users using paste and with paste all chars and special characters are allowed.

$(document).ready(function () {
          //called when key is down
          $("#recipient").bind("keydown", function (event) {
            if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 || event.keyCode == 188 ||
                // Allow: Ctrl+A
        (event.keyCode == 65 && event.ctrlKey === true) ||

        // Allow: Ctrl+C
        (event.keyCode == 67 && event.ctrlKey === true) ||

        // Allow: Ctrl+V
        (event.keyCode == 86 && event.ctrlKey === true) ||



        // Allow: home, end, left, right
            (event.keyCode >= 35 && event.keyCode <= 39)) {
              // let it happen, don't do anything
              return;
        } else {
            // Ensure that it is a number and stop the keypress
            if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
                event.preventDefault();
            }
        }
           });
        });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input class="form-control" type="text" id="recipient" name="recipient" required="required" minlength="9">

Update: You could use .replace() to filter nonnumeric into empty string and use input instead of keydown to get the correct value of current input

 $(document).ready(function () {
      //called when key is down
      $("#recipient").bind("input", function (event) {
        if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 || event.keyCode == 188 ||
            // Allow: Ctrl+A
    (event.keyCode == 65 && event.ctrlKey === true) ||

    // Allow: Ctrl+C
    (event.keyCode == 67 && event.ctrlKey === true) ||

    // Allow: Ctrl+V
    (event.keyCode == 86 && event.ctrlKey === true) ||



    // Allow: home, end, left, right
        (event.keyCode >= 35 && event.keyCode <= 39)) {
          // let it happen, don't do anything
          return;
    } else {
        // Ensure that it is a number and stop the keypress
        if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
            event.preventDefault();
            
        }
        console.log(event.target.value)
        var numeric = event.target.value.replace(/[^0-9,]/g, '')//replace non-numeric into empty string
        console.log('numeric', numeric)   
        $('#recipient').val(numeric)
    }
       });
    });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input class="form-control" type="text" id="recipient" name="recipient" required="required" minlength="9">

Block special charactes on paste event., Check the fields for "special" characters during paste,input,change,keyup events. JΛ̊KE. Leave a But had no luck so far. How to reference those textboxes and textareas and bind paste and input event to those in one go? I want to know if there are any jquery components which automatically take care of special characters. This basically means converting & to &amp and also all listed in here, so that when I send data to the backend it stores in that format. And then while retrieving we need to convert it back from &amp to &.


Maybe the most simple and clear way is to use a regex to replace invalid characters:

$(document).ready(function () {
  $("#recipient").bind("input", function (event) {
    $('#recipient').val($('#recipient').val().replace(/\D/g,""))
   });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input class="form-control" type="text" id="recipient" name="recipient" required="required" minlength="9">

Limit Character Input including Copy Paste in a Textbox or Textarea , Limiting character input in a textbox or textarea has its benefits, as it will restrict users solution that will limit character inputs in a textbox and textarea, including copy and paste. <html> <head> <title>Character limit in an InputBox</title> <​script How to Read Data from a Closed Excel File or Workbook without Opening it. Paste your copy from Word, or any other editor, into this tool first and it will strip out the following characters for you. It will give you a text and HTML version of your content. The HTML version will have paragraph tags around each block of text.


Javascript has a more simpler solution.

For formatting your phone number in real time as the user types, you can just get the values from the input box and then use,

input.oninput = function() {}

OR

For formatting your phone number stored in the clipboard, you can get the values from the clipboard by using

input.onpaste = function(event){}

You can make the functions that I've used smaller by removing the tempText & formattedText variables if you like, I used only them for code legibility and for the convenience of the user to use the variables elsewhere on the code.

/* Function 1 */
input.oninput = function() {
  var regExpr = /[^0-9,^,]/g; //If you don't want ',' comma then remove ^, from the code between [ ]
  var tempText = input.value;
  var formattedText = tempText.replace(regExpr, "");
  result.innerHTML = formattedText;
};

/* Function 2 */
input.onpaste = function(event) {
  var regExpr = /[^0-9,^,]/g; //If you don't want ',' comma then remove ^, from the code between [ ]
  var tempText = event.clipboardData.getData('text/plain');
  var formattedText = tempText.replace(regExpr, "");
  result.innerHTML = formattedText;
};
/*Has nothing to do with the paste formatting*/

body {
  display: flex;
  flex-direction: column;
  height: 80vh;
  justify-content: center;
  align-items: center;
  background: #222;
  color: #eee;
  text-align: center;
  font-family: monospace;
  font-size: 1.2em;
}

#input {
  text-align: center
}
<body>
  <div class="centerAll">
    <form>
      <label><b>Enter Phone Number</b></label><br/>
      <input type="phone" id="input" placeholder="Enter Phone Number...">
      <br/>
      <br/> Copy paste this:<br/>123-123-123,123<br/>
      <br/> Entered Phone number is:<br/>
      <span id="result"></span>
    </form>

  </div>
</body>

3ds Max 2012 Bible, You can cut, copy, and paste text into this text area from an external you open the Character Map application, you can see a complete list of special characters. I was looking for an answer that restricted input to only alphanumeric characters, but still allowed for the use of control characters (e.g., backspace, delete, tab) and copy+paste. None of the provided answers that I tried satisfied all of these requirements, so I came up with the following using the input event.


Kelly L. Murdock's Autodesk 3ds Max 2020 Complete Reference Guide, You can cut, copy, and paste text into this text area from an external application if To enter special characters into the text area in 3ds Max, choose the special  Hello! This page lets you generate special text symbols and all sorts of cool fancy text characters by simply typing your normal text in the first box, and then all the special text fonts will be output in the second box. You can copy and paste the special text into your Instagram bio, and to other places that support Unicode characters. I've


Autodesk 3ds Max 2013 Bible, You can cut, copy, and paste text into this text area from an external application if To enter special characters into the text area in 3ds Max, choose the special  If you use only keypress Then We Can Copy and paste special characters so use onpaste also to restrict Pasting special characters. Additionally, I will also suggest that you reconsider if you really want to prevent users from entering special characters. Because many people have $, #, @ and * in their passwords.


Not allow special characters to paste into text box in javascript, A quick and easy free tool to remove special characters from Word cut and pastes​. For use when pasting to your blog, article, sales page, or email newsletter. Copy Paste in VBA is similar to what we do in excel worksheet, like we can copy a value and paste it to another cell also we can use paste special to paste only the values, similarly in VBA we use the copy method with range property to copy a value from one cell to other and to paste the value we use the worksheet function paste special or paste method.