Validate a field which accept 0,1,2,3,4,5,6

Certified Senior Developer

HI Team,

I stuck on feild validation which will accept only below combination:

it can be 

0,1,2,3,4,5,6

or 0,1 or 1,2 combinations with all numbers or it can be only value which is less than 6 

I am able to achieve with below code

a!isNullOrEmpty(
stripwith(
ri!GBL_AutoCaseRunTimeConfig.config_value,
"0123456,"
)
)

but 

if user enters like 1,2,,,,,,, or 1,2,25 this is accepting , because it is under stripwith value i have added,  how can we validate ?

might be to use split with comma and use contains functions and also how we can remove comma at last ?

Any good suggestions ?

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    Are you saying the user enters a text value of like "0,1" or "0,1,2", ... "0,1,2,3,4,5,6", and those permutations?  It's a little unclear what the delineation is here between valid/expected inputs and invalid ones.

    Also: is it order independent?  Accepts multiple values? Etc?  You didn't specify, but if these are constraints we aren't worried about, then the following might work:

    a!localVariables(
      local!input,
      
      local!validSet: {1, 2, 3, 4, 5, 6, 0},
      
      a!textField(
        value: local!input,
        saveinto: local!input,
        
        validations: {
          if(
            and(
              a!isNotNullOrEmpty(local!input),
              or(
                a!forEach(
                  split(local!input, ","),
                  or(
                    fv!item <> tostring(tointeger(fv!item)),
                    not(contains(local!validSet, tointeger(fv!item)))
                  )
                )
              )
            ),
            "Invalid Entry",
            {}
          )
        }
      )
    )

    Valid:

    Invalid:

Reply
  • +1
    Certified Lead Developer

    Are you saying the user enters a text value of like "0,1" or "0,1,2", ... "0,1,2,3,4,5,6", and those permutations?  It's a little unclear what the delineation is here between valid/expected inputs and invalid ones.

    Also: is it order independent?  Accepts multiple values? Etc?  You didn't specify, but if these are constraints we aren't worried about, then the following might work:

    a!localVariables(
      local!input,
      
      local!validSet: {1, 2, 3, 4, 5, 6, 0},
      
      a!textField(
        value: local!input,
        saveinto: local!input,
        
        validations: {
          if(
            and(
              a!isNotNullOrEmpty(local!input),
              or(
                a!forEach(
                  split(local!input, ","),
                  or(
                    fv!item <> tostring(tointeger(fv!item)),
                    not(contains(local!validSet, tointeger(fv!item)))
                  )
                )
              )
            ),
            "Invalid Entry",
            {}
          )
        }
      )
    )

    Valid:

    Invalid:

Children