I have a <input type="email"/>
and want it to
a) be a valid email address and
b) be something other than a given email address - let's say "root@localhost".
I had a look into the Pattern for HTML input elements and now I try to write a pattern excludes a specific value.
I stumbled across this Post: A regular expression to exclude a word/string and looked into negative look ahead, which was quite promising. Except for one thing:
If I use negative lookahead, it will also match anything that starts with the given exlusion, not only those that exactly match it!
My Code:
<input type="email" name="email" pattern="^(?!root@localhost).+$" required>
This will result in a validation error for
- empty text (correct)
- non-email-texts (correct)
- an email-address of "root@localhost" (correct)
- any email addresss starting with "root@localhost" (wrong)
Can you please help me on how to write a pattern that excludes exactly one email address from the validation?
Is using a pattern the right way here?
Thanks,
Alexander