amacdonald amacdonald - 1 month ago 4x
Javascript Question

Prevent a specific special character from appearing ANYWHERE within a string with Regex?

I'm doing a VERY VERY simple regex, which is:


All I'm trying to do is throw something in there that will fail if there is a
or a
ANYWHERE in the string.

My original thought was just this:
, but this only fails if the < or the > are at the beginning or the end of the string. Is there a simple command I'm missing so that it'll fail if either of those characters are anywhere in the string?

Amy Amy

Why use regex? That seems like overkill, and there is nothing simple about regex.

Why not just use the includes() function instead?

!str.includes(">") && !str.includes("<")