Word restriction

Asked

Viewed 280 times

0

Speak, folks.

I’d like to know how to restrict certain words, like, a person tries to write 'PQP', so the site doesn’t let this word stay there.

HTML5 - CSS - JS

  • 1

    Saves a Blacklist of words you do not want to accept in an array with javascript, ai only checks the word when the user does some action.

  • 1

    You will need a programming language, make a list of words you don’t want, and use functions to block these words.

1 answer

1


Good though you can do in HTML as well.

<form action="">
  Palavra : <input type="text" name="palavra" pattern="^((?!PQP).)*$">
  <input type="submit">
</form>

Thus the string "PQP" is not allowed. If the answer is correct, I could validate it.

To assemble expressions for multiple words you will need the operator "or"("|").

Here you can see how to make the expressions

  • When you see that message saying "You need the format to match the required", can I change the text of the message?? If so, how can I change it?

  • And how can I add more words to the PATTERN tag?

  • To change the message you can use the attribute oninvalid="setCustomValidity('Your message')"... To add more words in the regular expression, you will need to use the"|" "or" operator, I recommend reading the link about expressions I left...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.