How to exclude html tags validation in object value?

  • 0
    There is a component with a text editor for filling out a form, the value of which contains html tags for formatting. That is, if the following text is entered in the field:


    it will remain in this form:

    description: "<p>Please note that only the <strong>first 120 characters</strong> will always 
    be displayed when you share the event via social media. </p>"


    This field is required, and if it is empty, do not let the user go further.
    The problem is that if you clear all the text from the input, the html tags will remain, and the value will look like this:

    description: "& lt; p & gt; & lt; br & gt; & lt; / p & gt;"

    Because of this, the form considers itself complete and skips the user further.
    How to write a check for such a case correctly so that it excludes the presence of html tags?
    JavaScript Anonymous, Jun 4, 2020

  • 1 Answers
  • 0
    Check not innerHTML but textContent





    trim () would also be nice to call to exclude spaces.
    Kira Bentley

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!