I have two fields. Textarea and input type text. They have several tags, such as <firstname> . I want to make them unedited for users. and if he tries to remove the entire tag, it is deleted. here is the js violin
I'm trying with this
$(function () { var tb = $("#t").get(0); $("#t").keydown(function (event) { var start = tb.selectionStart; var end = tb.selectionEnd; var reg = new RegExp("(<.+?>)", "g"); var amatch = null; while ((amatch = reg.exec(tb.value)) != null) { var thisMatchStart = amatch.index; var thisMatchEnd = amatch.index + amatch[0].length; if (start <= thisMatchStart && end > thisMatchStart) { event.preventDefault(); return false; } else if (start > thisMatchStart && start < thisMatchEnd) { event.preventDefault(); return false; } } }); });
but it does not work.
it only works for this, if the cursor is at the beginning of the tag, then it is not editable. But if the cursor is at the end of the tag, this is edited. I want to make this completely inconclusive.
source share