You cannot practically protect part of the text field. In fact, you can try to block the input of clicks when the cursor is inside the template {...}, but there are so many other ways to edit it, for example. select a range, then delete / replace, cut / copy / paste, drag and drop ...
textarea , - , :
<textarea id="mail_text">...</textarea>
<div id="mail_text_warning"></div>
<script type="text/javascript">
function checkMailText() {
var tokens= ['username', 'recipient', 'salutation'];
var value= $('#mail_text').val();
var problems= [];
$.each(tokens, function() {
if (value.split('{'+this+'}').length!==2)
problems.push('Please ensure there is one and only one {'+this+'} token present in the text');
});
matches= value.match(/\{[^\}]*\}/g);
if (matches!==null) {
$.each(matches, function() {
for (var i= tokens.length; i-->0;)
if ('{'+tokens[i]+'}'===this)
return;
problems.push('Token '+this+' is not known');
});
}
$('#mail_text_warning').text(problems.join('. '));
}
setInterval(checkMailText, 500);
</script>