I need to check the width of text that a user enters and not allow any further entry if it exceeds a maximum value. I know how to measure the width of the text in a div, using the current font and font size. I test the width of the text with the following function:
editor.on("change", function (ev) {
var imprintText = editor.getData();
var textWidth = measureText(imprintText);var hfMaxImprintWidth = document.getElementById("<%=hfMaxImprintWidth.ClientID%>");
var maxWidth = hfMaxImprintWidth.value;if (textWidth >= maxWidth) {
};
});
But I don't know how to keep additional characters from being added to the textarea. I'd also like to limit the text to one line (no line breaks or new paragraphs). Can someone please help me with this? Thanks!
