Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Regex Validation on Text Area form elements

Vote:
 

Does the regex validator act as a whitelist or a blacklist?
I'm still confused by how to use it properly.
I want to NOT allow end users to enter URLs into a text area element.
Should I be looking to create a regex that defines what I allowing or what I want to exclude.
I can't seem to get it working either way.

#316856
Feb 08, 2024 0:00
Vote:
 

The regex validator acts as a whitelist in that the string the user enters must match the regex entered so you would have to create a regex which defines what you want to allow. Specifying a string you don't want to appear is quite a bit trickier than specifying what you do want to see but it should be possible with a negative lookahead operator or similar, something like this: ^((?!:\/\/).[\r\n]*)*$

#316868
Feb 08, 2024 14:58
LarryVictorio - Feb 08, 2024 17:02
Thanks Paul, this is awesome. Just to clarify, this pattern is looking for strings that don't contain :// correct?
Paul Gruffydd - Feb 08, 2024 17:12
Yep. That's correct.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.