A HTML-only solution with no coding required is using the "plaintext-only" type for contentenditable elements:
<div contenteditable="plaintext-only">This text can be edited by the user.</div>
See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/contentEditable