Detect unadmitted tags by specifying the admitted ones in a textarea using JQuery or Javascript and if a button it's clicked remove it

Viewed 52

I'm going mad because I want to give to the user a feedback about the tags unadmitted in a textarea.

There's a way to detect unadmitted tags in a textarea by specifying the admitted ones?

like

<script>
var admittedTagsArray = ['a','p','div'];

function arrayDetectUnadmittedTagsBySpecifyingTheAdmittedOnes(admittedTagsArray,textarea.val()) {
   [...]  <<  I donno know what
   return unadmittedTagsArray;
}

function buttonClickedRemoveUnadmittedTagsBySpecifyingTheAdmittedOnes(admittedTagsArray,textarea.val()) {
   var previoustextareaval = textarea.val()
   var newtextareaval = '';
   [...]  <<  I donno know what
   textarea.val(newtextareaval):
}

//sumbit
$.each( arrayDetectUnadmittedTagsBySpecifyingTheAdmittedOnes, function( k, v ) {
    alert(v+'is unadmitted');
});
</script>

Example of scenario using a demonstrative text (requested in comments)

<textarea id="dt" onchange="arrayDetectUnadmittedTagsBySpecifyingTheAdmittedOnes();">
<html>
<head>
</head>
<body>
Book traversal <a href="https://stackoverflow.com">links</a> for Demonstratives.
<p>Do you need to improve your English grammar?</p>
Join thousands of learners from around the world who are improving....


A demonstrative <span>pronoun</span> is a pronoun that is used to point to something specific within a sentence.
These pronouns can indicate items in space or time.

</body>
</html>
</textarea>

Now, listen, because admittedTagsArray does not contains the span tag:

$.inArray('span',admittedTagsArray) == -1

but also html, body,head append a button over textarea like this

<button type="button" onclick="buttonClickedRemoveUnadmittedTagsBySpecifyingTheAdmittedOnes();">Remove tags</button>

that if clicked shoud gives the result:

<textarea id="dt" onchange="arrayDetectUnadmittedTagsBySpecifyingTheAdmittedOnes();">
Book traversal <a href="https://stackoverflow.com">links</a> for Demonstratives.
<p>Do you need to improve your English grammar?</p>
Join thousands of learners from around the world who are improving....


A demonstrative pronoun is a pronoun that is used to point to something specific within a sentence.
These pronouns can indicate items in space or time.

</textarea>

Or, that you know there's a tool that does this?
0 Answers
Related