Reputation: 24
Whenever i paste text in textarea , it should strip the character like <,>,@ etc. i try in JQuery
$('input').on('paste', function () { var element = this; setTimeout(function () { var text = $(element).val(); // do something with text }, 100); });
$('input').on('paste', function () {
var element = this;
setTimeout(function () {
var text = $(element).val();
text.replace('<', '') );
}, 100); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="test" name="test" style="height:300px; width:400px"></textarea>
Upvotes: 1
Views: 2735
Reputation: 388436
You are using input
element selector which matches only elements with tagname as input
like <input type="..." />
, instead of textarea
so
$('textarea').on('paste', function() {
var $el = $(this);
setTimeout(function() {
$el.val(function(i, val) {
return val.replace(/[<>@]/g, '')
})
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<textarea id="test" name="test" style="height:300px; width:400px"></textarea>
Upvotes: 2