S
S
ShadowTrix2022-02-23 21:52:06
JavaScript
ShadowTrix, 2022-02-23 21:52:06

In JS check for characters between certain tags?

I'm trying to use JS to check that the text message being sent is not empty.

Since I use the TinyMCE editor, it is html that needs to be checked, and not just text.

If text, then everything is simple:

const text = editor.getContent({format: 'text'}).replace(/\s+/g,' ').trim();

if(text === '' || !text) {
  return false;
}


But, since this is a visual editor, there may be such embeds as etc. without any text inserts between tags. Accordingly, the above code will return an error during such posting. If you allow to take content as html, then double spaces are skipped, etc. In the config, they are used as root for the text, that is, it will always be in the message code initially. Hence, the idea arose to check that in the source code of the message after the first tag there is any character, except for spaces and tabs. Question: how to do this using regular expressions in JS? Maybe you have a simpler and better method. Thanks for any suggested solution. <iframe>, <video>, <audio>


<div>
<div> ...message... </div>

<div>


Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question