Hi all.
I'm having some syntax issues with the regex function added to the constraints field. If anyone can show me where I'm going wrong, that'll be great.
I have some special characters in a text field that I don't want to allow. If the user populates the text field with one or more of these characters, I want the validation to fail with an error message. The special characters I do NOT allow are: " or ` or > or < or ; or \.
I tried the following (and various iterations of it);
regex(.,'([^<>";])')
but once I add the ' or the \, it fails to refresh the survey.
regex(.,'(^[a-zA-Z0-9,*!£%^&)(+=@:#~/?. ]+$)')
where I add all the characters I want to allow, but this fails to refresh when I add { or } or [ or ].
Any help appreciated.
Regards
Schalk
Solved! Go to Solution.
The reason why it won't work with \ and ' is because \ is used to escape characters using regex, and ' is used to enclose the string.
I got this to work by escaping the \, then creating a separate string and substituting it into the expression.
I used a hidden field named "characters" and set the default to the string I want to use: ^[^<>";\\']+$
Then in the constraint field for the input: regex(.,${characters})
The reason why it won't work with \ and ' is because \ is used to escape characters using regex, and ' is used to enclose the string.
I got this to work by escaping the \, then creating a separate string and substituting it into the expression.
I used a hidden field named "characters" and set the default to the string I want to use: ^[^<>";\\']+$
Then in the constraint field for the input: regex(.,${characters})
Works a charm. Thanks very much Stephen!