0

So I have a input like:

<input type="text"
    name="firstname"
    id="firstname"
    placeholder="Name"
    maxlength="15"
    pattern="^[a-zA-ZąćęłńóśżźĄĆĘŁŃÓŹŻŚ]+$"
    autofocus
    required >

Now I need to add another 'validation' what detect if in this input appear one of the following words: ['dog', 'cat']

So I would like to add patern or something else what check if input pass pattern="^[a-zA-ZąćęłńóśżźĄĆĘŁŃÓŹŻŚ]+$" and do not let any word from this array ['dog', 'cat'] pass

LiOne
  • 17
  • 1
  • 5
  • 3
    Does this answer your question? [A regular expression to exclude a word/string](https://stackoverflow.com/questions/2078915/a-regular-expression-to-exclude-a-word-string) – JSON Derulo Dec 06 '21 at 12:34

1 Answers1

1

maybe using lookahead, try replacing your pattern for:

(?=^[a-zA-ZąćęłńóśżźĄĆĘŁŃÓŹŻŚ]+$)(?=^(?!.*cat|.*dog).*$)
Pedreiro
  • 1,641
  • 2
  • 18
  • 28