Hello I have a situation where user can input URI for a page in a cms and I would like to prevent them entering some characters such as ?
or :
which will break the URL.
In the end the goal is to have "https://somesite.com/USER_DEFINED_VARIABLE
/"
I need a regex for the form validation where I check invalid characters.
I think it should be the opposite of this: SLUG_REGEXP = '[0-9A-Za-z-_.//]+'
But I don't know how to do it. Thanks in advance.
Asked
Active
Viewed 10 times
-1
![](../../users/profiles/11415360.webp)
moddayjob
- 159
- 9
-
`[0-9A-Za-z_./-]+` is a positive character class. `[^0-9A-Za-z_./-]+` is a negated character class. If you use `^[^0-9A-Za-z_./-]+$` it will match any string that does not contain the specified chars. – Wiktor Stribiżew May 27 '21 at 15:35
-
I don't want that. I want these characters to be allowed but only `:` or `?` or some others that might break my URL not to be allowed. Thanks though – moddayjob May 27 '21 at 15:37
-
So, use a negated character class with those chars. – Wiktor Stribiżew May 27 '21 at 15:38