I am looking to limit what a user can input into a field based on previous entries that already exist.
For example, a user has entered these values into the database already:
["typescript", "C#", "python"]
When they type one of these already existing values into the input field EXACTLY, I want the validator message to appear.
I have this negative look ahead Regex from another answer I found:
^(?!.*(typescript|C#|python)).*$
but it will fail validation if one of those words appears anywhere in the input string (for example: "pythons" would fail). I just want it to fail if one of those words appear exactly in the input.
EDIT
I ended up using the custom validator solution provided below. The regex solution below did also work. As discussed, validators are the correct solution for this particular issue.
As you are preferring to look for a regex solution, you can use this regex to reject matches when it is exactly any one of these,
typescript
C#
python
The negative look ahead you wanted to use needs to be written like this,
^(?!(?:typescript|C#|python)$).+$
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments