How to escape special chars - (for example, / \ ; : " | ? ' < > * ).

Example - 

Validation: Filename cannot contain special characters (for example, / \ ; : " | ? ' < > * ). 

Expression evaluation error: Syntax error. Details: Expression evaluation error : Invalid character found in expression: | 

  Discussion posts and replies are publicly visible

Parents Reply
  • that did not work - need to show the validation message on the screen for fileupload component 


    a!fileUploadField(
    label: "Upload File",
    target: cons!FOLDER_CONSTANT,
    value: ri!uploadedFile,
    saveInto: ri!uploadedFile,

    validations: if(
    and(
    not(isnull(ri!uploadedFile)),
    length(stripwith(ri!uploadedFile.name, "\ / ; : "" | ? ' < > *")) <> length(ri!uploadedFile.name)
    ),
    "Filename cannot contain special characters (for example, / \ ; : " | ? ' < > * )."
    null
    )
    )

Children
  • 0
    Certified Associate Developer
    in reply to ravib950399

    Try this:

    a!localVariables(
      local!file,
      {
        a!fileUploadField(
          label: "Upload File",
          target: cons!FOLDER_CONSTANT,
          value: local!file,
          saveInto: local!file,
          validations: {
            if(
              a!isNullOrEmpty(fv!files),
              null,
              if(
                regexmatch(
                  pattern: "[\\/;:""|?'<>*\]\[]",
                  searchString: trim(fv!files.name),
                ),
                "Filename cannot contain special characters (for example, / \ ; : "" | ? ' < > * ).",
                null
              )
            )
          },
          maxSelections: 1
        )
      }
    )