Skip to main content
mohammedmujaheedp3225
January 12, 2023
Question

Validation for Text field for country calling codes

  • January 12, 2023
  • 4 replies
  • 0 views

Hi All,

I have a requirement where i have to add  validation on a text field and the validation is like + and three integer.

please help me out with this.

thanks. 

    4 replies

    harshitb6843
    January 12, 2023

    You can use the code below for it. 

    and(
      len(ri!text)<=4,
      a!forEach(
        items: code(ri!text),
        expression: or(
          fv!item=43,
          and(
            fv!item>=48,
            fv!item<=57
          )
        )
      )
    )

    harshitb6843
    January 12, 2023

    Here is another variant of it where the first character has to be a "+"

    and(
      len(ri!text)<=4,
      a!forEach(
        items: code(ri!text),
        expression: if(
          fv!isFirst,
          fv!item=43,
          and(
            fv!item>=48,
            fv!item<=57
          )
        )
        
      )
    )

    jonesprakashs0001
    January 12, 2023

    The below code also should work. If the first character has to be a "+" and the rest should be three number digits

    regexmatch(
      "^\+([0-9]{3})$",
      ri!text
    )

    csteward
    January 12, 2023

    Note the regexmatch() solution does require to install the Regular Expressions Functions plugin.  Otherwise there are a number of ways to do this OOTB.  Another example:

    and(
      len(ri!text)=4,
      code(left(ri!text,1))=43,
      tointeger(right(ri!text,3))=right(ri!text,3)
    )