Skip to main content
September 5, 2022
Question

Is there a method to restrict the use of special characters other than "space, (), [], and []"

  • September 5, 2022
  • 4 replies
  • 0 views

Hello,

Is there a method to restrict the use of special characters other than "space, (), [], and <>" in the text field or paragraph field?

Kind of thinking using validation.

Thank you.

    4 replies

    September 5, 2022

    You have to use regex to restrict it. 

    harshitb6843
    September 5, 2022

    There are many ways of doing it One of the methods that I use the most is to see Stripwith() function to remove all the special characters and then compare the length of the two strings. Also, isolate this in a rule so you can add or remove characters in the future with ease. 

    September 5, 2022

    You can try this :

    a!localVariables(
    local!allspecialCharacters: "`!@#$%^&*-_={}|\/:;'"",.?",
    local!textField: "",
    a!textField(
    label: "Text",
    labelPosition: "ABOVE",
    value: local!textField,
    saveInto: { local!textField },
    refreshAfter: "UNFOCUS",
    validations: {
    if(
    len(local!textField) = 0,
    null,
    if(
    len(local!textField) > len(
    stripwith(
    local!textField,
    local!allspecialCharacters
    )
    ),
    "Special Characters not allowed",
    null
    )
    )
    }
    )
    )

    September 5, 2022

    Thank you.

    I kind of made it like 

    a!isNullOrEmpty(
      concat(
        a!forEach(
          items: {
            "`","~","!","@","#","$","%","^","&","*","_","-","=","/","?","{","}",";",":"
          },
          expression: {
            if(
              search(fv!item, ri!textField, 1) = 0,
              {},
              1
            )
          }
        ),
      )
    )

    but, think yours is better.