RE: Validation

if(
  ri!valueType_txt = "Ratio",
  if(
    and(
      like(ri!inputValue_txt, "*:*"),
      isnull(
        stripwith(ri!inputValue_txt, "1234567890:.")
      ),
      not(
        isnull(stripwith(ri!inputValue_txt, ":."))
      ),
      left(ri!inputValue_txt) <> ":",
      right(ri!inputValue_txt) <> ":"
    ),
    "",
    cons!CR_APP_COV_THRESHOLD_VALIDATION_MSG[1]
  ),
  if(
    ri!valueType_txt = "Ratio:1",
    if(
      and(
        like(ri!inputValue_txt, "*:1"),
        isnull(
          stripwith(ri!inputValue_txt, "1234567890:.")
        ),
        not(
          isnull(stripwith(ri!inputValue_txt, ":."))
        ),
        left(ri!inputValue_txt) <> ":",
        right(ri!inputValue_txt) <> ":"
      ),
      "",
      "Value is not in the format of m:1."
    ),
    if(
      ri!valueType_txt = cons!CR_APP_FIN_COV_VALUE_TYPES[3],
      if(
        and(
          len(
            stripwith(ri!inputValue_txt, "0123456789.")
          ) = 0,
          len(cleanwith(ri!inputValue_txt, ".")) < 2
        ),
        if(
          and(
            len(
              cleanwith(ri!inputValue_txt, "0123456789")
            ) < 15
          ),
          "",
          cons!CR_APP_COV_THRESHOLD_VALIDATION_MSG[3]
        ),
        cons!CR_APP_COV_THRESHOLD_VALIDATION_MSG[4]
      ),
      if(
        ri!valueType_txt = cons!CR_APP_FIN_COV_VALUE_TYPES[4],
        if(
          and(
            len(
              stripwith(ri!inputValue_txt, "0123456789.%")
            ) = 0,
            len(cleanwith(ri!inputValue_txt, ".")) < 2
          ),
          "",
          cons!CR_APP_COV_THRESHOLD_VALIDATION_MSG[4]
        ),
        ""
      )
    )
  )
)

Hi Everyone, I am looking for a solution related to when valueType= "Ratio:1", then the upto 3 decimals on left side:1 ,need to restrict values which are entered more than 4 decimals in left only, How Can I do that,Can anyone help to do that?

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    Hi JS,

    Over all as far i understand , after the ratio in the provided text by user, you should allow only three characters after ratio, if its more than three you should show an message right?

    see if the below logic works

    a!localVariables(
    
    local!splitValues:split("ABC:12323",":"),
    
    
    
    if(len(index(local!splitValues,2,""))>3,"Greater than three","Good")
    
    )

    if this is not what you are expecting, can you help with user input and what validation you are trying to perform.

  • 0
    Certified Lead Developer

    I have a hard time understanding your explanation. Can you help me?

  • ok, So we have value type in ui has ratio:1 type that means user can enter value has 5.6678435.1 format ,but instead of entering more that 3 decimals ,we need to restrict up to 3 decimals only. I hope now this sentence understandable.

  • not after ratio,before ratio,ok let me give example to u, value = 2.655:1

  • 0
    Certified Senior Developer
    in reply to JS0001
    5.6678435.1 format

    You mean 5.6678435:1

  • 0
    Certified Lead Developer
    in reply to JS0001

    Hm ... didi you consider to use two fields for this? That would make the validation much easier and the user would not have to enter the colon.

    Then, why not just round the entered value to three decimals?

  • 0
    Certified Senior Developer

    Hello  
    I made changes to your provided code to meet your requirement. Validate once and let me know if that works for you.
    This ensures only values with a maximum of 3 decimals on the left side are allowed.

    if(
      ri!valueType_txt = "Ratio",
      if(
        and(
          like(ri!inputValue_txt, "*:*"),
          isnull(
            stripwith(ri!inputValue_txt, "1234567890:.")
          ),
          not(
            isnull(stripwith(ri!inputValue_txt, ":."))
          ),
          left(ri!inputValue_txt) <> ":",
          right(ri!inputValue_txt) <> ":"
        ),
        "",
        cons!CR_APP_COV_THRESHOLD_VALIDATION_MSG[1]
      ),
      if(
        ri!valueType_txt = "Ratio:1",
        if(
          and(
            like(ri!inputValue_txt, "*:1"),
            isnull(
              stripwith(ri!inputValue_txt, "1234567890:.")
            ),
            not(
              isnull(stripwith(ri!inputValue_txt, ":."))
            ),
            left(ri!inputValue_txt) <> ":",
            right(ri!inputValue_txt) <> ":"
          ),
          "",
          "Value is not in the format of m:1."
        ),
        if(
          ri!valueType_txt = cons!CR_APP_FIN_COV_VALUE_TYPES[3],
          if(
            and(
              len(
                stripwith(ri!inputValue_txt, "0123456789.")
              ) = 0,
              len(
                index(
                  split(
                    left(
                      ri!inputValue_txt,
                      find(":", ri!inputValue_txt) - 1
                    ),
                    "."
                  ),
                  2,
                  {}
                )
              ) <= 3,
            ),
            if(
              and(
                len(
                  cleanwith(ri!inputValue_txt, "0123456789")
                ) < 15
              ),
              "",
              cons!CR_APP_COV_THRESHOLD_VALIDATION_MSG[3]
            ),
            cons!CR_APP_COV_THRESHOLD_VALIDATION_MSG[4]
          ),
          if(
            ri!valueType_txt = cons!CR_APP_FIN_COV_VALUE_TYPES[4],
            if(
              and(
                len(
                  stripwith(ri!inputValue_txt, "0123456789.%")
                ) = 0,
                len(cleanwith(ri!inputValue_txt, ".")) < 2
              ),
              "",
              cons!CR_APP_COV_THRESHOLD_VALIDATION_MSG[4]
            ),
            ""
          )
        )
      )
    )

  • Hi ,I have tried with this code for the  value Type=Ratio:1 type, Coz I needed  validation for that value type(Ratio:1), I am getting this validation in ui

    if(
      ri!valueType_txt ="Ratio",
      if(
        and(
          like(ri!inputValue_txt, "*:*"),
          isnull(
            stripwith(ri!inputValue_txt, "1234567890:.")
          ),
          not(
            isnull(stripwith(ri!inputValue_txt, ":."))
          ),
          left(ri!inputValue_txt) <> ":",
          right(ri!inputValue_txt) <> ":"
        ),
        "",
        "Value is not in the format of m:n."
      ),
      if(
        ri!valueType_txt = "Ratio:1",
        if(
          and(
            like(ri!inputValue_txt, "*:1"),
            isnull(
              stripwith(ri!inputValue_txt, "1234567890:.")
            ),
            not(
              isnull(stripwith(ri!inputValue_txt, ":."))
            ),
            left(ri!inputValue_txt) <> ":",
            right(ri!inputValue_txt) <> ":",
            len(
              stripwith(ri!inputValue_txt, "0123456789.")
            ) = 0,
            len(
              index(
                split(
                  left(
                    ri!inputValue_txt,
                    find(":", ri!inputValue_txt) - 1
                  ),
                  "."
                ),
                2,
                {}
              )
            ) <= 3,
            
          ),
          "",
          "Value is not in the format of m:1."
        ),
        if(
          ri!valueType_txt = "Amount",
          if(
            and(
              len(
                stripwith(ri!inputValue_txt, "0123456789.")
              ) = 0,
              len(cleanwith(ri!inputValue_txt, ".")) < 2
            ),
            if(
              and(
                len(
                  cleanwith(ri!inputValue_txt, "0123456789")
                ) < 15
              ),
              "",
              "Value cannot be more than 14 digit numbers."
            ),
            "Invalid value entered."
          ),
          if(
            ri!valueType_txt = "Percentage",
            if(
              and(
                len(
                  stripwith(ri!inputValue_txt, "0123456789.%")
                ) = 0,
                len(cleanwith(ri!inputValue_txt, ".")) < 2
              ),
              "",
              "Invalid value entered."
            ),
            ""
          )
        )
      )
    )

  • 0
    Certified Senior Developer
    in reply to JS0001

    As you mentioned earlier
    user can enter value as 5.6678435:1 format ,but instead of entering more that 3 decimals ,we need to restrict up to 3 decimals only.
    That what code is doing. It's restricting user using validation.

     Am i missing something?

  • yes Now In the UI ,I have entered Upto 3 decimals but validation is throwing.