String validation

A Score Level 1

Hi , 

How can we apply string data validation in the textfield in Appian. I have a requirement in which the first two alpahbets, should  be either a or A and the second one will be c or C. In short for a particular string , how can i check the character value at a particular index and apply validation.

  Discussion posts and replies are publicly visible

  • 0
    A Score Level 1
    in reply to ST07

    included a null check also for this , 

    a!dropdownField(
    choiceLabels: {
    "jan,feb,march"
    },
    choiceValues: {
    "jan,feb,march"
    },
    value: if(isnull(local!month),{},local!month),

    i am not sure how this thing works, initially year and month variables will be null only , user will enter the values.

  • +1
    Certified Lead Developer
    in reply to ST07

    When you have a dropdown field whose value will initially be null (so, most of the time), you need to also set a "placeholder label" value -- this is usually just text that will help the user know what to do, and shows up when the value is NULL, but doesn't count as a valid selection if the field is required.  Setting this correctly will cause your error message to go away.

    e.g.

    a!localVariables(
      local!year,
      a!dropdownField(
        choiceLabels: {
          "2020",
          "2021",
          "2022"
        },
        choiceValues: {
          "2020",
          "2021",
          "2022"
        },
        value: local!year,
        saveInto: local!year,
        placeholderLabel: "--Select Year--"
      )
    )

    (also, i fixed the choiceLabels and choiceValues - these should be arrays, the way you had them they were just strings that would cause them to only show up as one option instead of three)

  • 0
    A Score Level 1
    in reply to Mike Schmitt

    Thanks mike , both the approach works fine.  I had this last doubt , like in documentation how is text(38353, "mmm/dd/yyyy")   returns "Jan/03/2140"(Text)     . Actually i thought of using text function to convert input value to date type string. How this date is being calculated?

  • 0
    Certified Lead Developer
    in reply to ST07

    In general for dates, the text function is really only useful if the value you're starting with is an actual date value - i.e. "text(now(), "mmm/yyyy")" would work well, but i don't know if it would work very well with inputs that aren't a date value or something corresponding to this.

  • 0
    Appian Employee
    in reply to ST07

    There's two things going on here. First is the representation of a date value as a number. If you ever try to convert a date to an integer, the number represents the number of days before or after 1 January 2035 (see the todate() function docs for more information). So in the case you gave above, 38353 is considered that many days after 1 Jan 2035, which results in 3 Jan 2140.

    The second thing to consider is the method Appian uses to display dates using the text function. The text function can display many kinds of date formats depending on what format is provided as the second parameter. For example, the following options all display some kind of month:

    • "m" --> returns the month number without leading zeros; for example, January would be 1 and November would be 11
    • "mm" --> returns the month number with leading zeroes; for example, January would be 01 and November would be 11
    • "mmm" --> returns the three letter name of a month; for example January would be Jan and November would be Nov
    • "mmmm" --> returns the full month name

    All that being said, this function is used to go from a number to a string, but I believe you want the opposite (go from the text month name to a number). The best way to do this is to use choiceValues to save the number for month instead of the text name like this:

    a!localVariables(
      local!month,
      a!dropdownField(
        choiceLabels: {
          "Jan",
          "Feb",
          "Mar"
        },
        choiceValues: {
          "01",
          "02",
          "03"
        },
        value: local!month,
        saveInto: local!month,
        placeholderLabel: "--Select Month--"
      )
    )

  • 0
    A Score Level 1
    in reply to Peter Lewis

    ohh , thanks for the detailed explanation . So , i think as of now , we dont have any fuction to validate input string as a date format. We have to make customized validation check for that or using regex functions.