I would like to validate that there are no apostrophes ('
) in a data element (valuetype text) with d2:validatePattern
(docs).
What I tried:
blocklist (not allowing the apostroph in the value):
d2:validatePattern( #{text_de}, '.*\'.*' )
d2:validatePattern( #{text_de}, '.*\\'.*' )
d2:validatePattern( #{text_de}, '.*\\\'*.' )
d2:validatePattern( #{text_de}, '.*\\\\'*.' )
d2:validatePattern( #{text_de}, '.*\\\\\'*.' )
switching out the enclosing apostrophes to "
d2:validatePattern( #{text_de}, ".*\'.*" )
allowlist (checking if the value matches a pre-defined character set):
!d2:validatePattern( #{text_de}, '^[a-zA-Z0-9\\s]+$' )
alternative functions:
splitting value by the apostroph and checking if the first part is not empty:
d2:hasValue( #{text_de} ) && d2:split( #{text_de}, '\'', 0) != ''
They all do not trigger when a user enters an apostroph. Is there a way to achieve this?