Skip to main content
January 2, 2023
Question

validation for text field

  • January 2, 2023
  • 5 replies
  • 0 views

hi,

i use 22.3 version

i have an condition in text field 

in that i want only alphabetical character (A-Z) not numerical or special character

how to do that

    5 replies

    January 2, 2023

    You can use regexMatch function to make it according to regex. But for than you have to deploy Regex expression plugin in your environment

    harshitb6843
    January 2, 2023

    If you do not want to add a dependency on the plugin, then you can use this code. 

    if(
      and(
        a!forEach(
          items: code(ri!name),
          expression: or(
            and(fv!item >= 65, fv!item <= 90),
            and(fv!item >= 97, fv!item <= 122)
          )
        )
      ),
      {},
      "Cannot contain numbers or special characters"
    )

    Known Participant
    January 2, 2023

    you can try this.

    if(
    contains(
    cast(
    runtimetypeof(ri!input),
    stripwith(
    cleanwith(
    ri!input,
    joinarray(
    {
    "abcdefghijklmnopqrstuvwxyz",
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    }
    )
    ),
    " "
    )
    ),
    ri!input
    ),
    "",
    "Please use alphabetical characters only."
    )

    harshitb6843
    January 2, 2023

    Simplified it a bit. 

    if(
      a!isNotNullOrEmpty(
        stripwith(
          ri!name,
          lower("ABCDEFGHIJKLMNOPQRSTUVZXYZ") & "ABCDEFGHIJKLMNOPQRSTUVZXYZ"
        )
      ),
      "Can only contain alphabets",
      {}
    )

    Known Participant
    January 2, 2023

    cool, :)