Skip to main content
saurabhs0003
May 17, 2021
Solved

validate email address without Regex

  • May 17, 2021
  • 6 replies
  • 0 views

please tell me how to validate email address without regex means with the help of like function . 

I am writing this expression : like(ri!email,"*@gmail.com") 

but i want to validate every field like first character should not be digit and all .help me to sort out this 

    Best answer by mikes0011

    Thanks [mention:126a676c85024855948336691b0a7b92:e9ed411860ed4f2ba0265705b8793d05]!  The above code, as its own expression rule, has helped me out in various different Appian projects since I originally wrote it, especially those where we didn't (yet) have the RegEx plug-in.  For what it's worth, since then I've swapped it out with the actual RegEx functionality as it's able to handle a little bit more.  [mention:80250d04270e449fb1b32cc9aa5c1ef4:e9ed411860ed4f2ba0265705b8793d05] is there a reason you can't use the RegEx plug-in?

    Here's the current code (still in an expression rule i.e. `UTIL_isValidEmailAddress()`) --

    regexmatch(
      pattern: "^[A-Z0-9\_-]+(\.{0,1}[A-Z0-9\+_-]+)*[@]{1}[A-Z0-9.-]*[A-Z0-9-]+[.]{1}[A-Z]{2,6}$",
      searchString: ri!email,
      regexFlags: "si"
    )

    6 replies

    stefanhelzle0001
    Brainy
    May 17, 2021

    Thanks to [mention:b45a4f6a20b14a008e4e0ec732a8bf98:e9ed411860ed4f2ba0265705b8793d05] there is existing code.

    community.appian.com/.../way-to-validate-email-addresses

    After reading this

    https://stackoverflow.com/questions/2049502/what-characters-are-allowed-in-an-email-address

    I think that email address validation is pretty ugly and not doable without regex. In case you want to rule out the most simple typos, then go with Mikes code. I just updated it to comply with latest changes in Appian

    a!localVariables(
      local!trimmed: trim(ri!address),
      if(
        or(
          isnull(local!trimmed),
          len(local!trimmed) > 255,
          length(split(local!trimmed, " ")) > 1,
          count(split(local!trimmed, "@")) <> 2
        ),
        false(),
        a!localVariables(
          local!localPart: split(local!trimmed,"@")[1],
          local!domainPart: split(local!trimmed,"@")[2],
          if(
            or(
              length(split(local!domainPart, ".")) < 2,
              contains(split(local!localPart, "."), ""),
              contains(split(local!domainPart, "."), ""),
              not(isnull(stripwith(lower(local!domainPart), "abcdefghijklmnopqrstuvwxyz1234567890-."))),
              not(isnull(stripwith(lower(local!localPart), "abcdefghijklmnopqrstuvwxyz1234567890-._+'&%")))
            ),
            false(),
            true()
          )
        )
      )
    )

    mikes0011
    mikes0011Answer
    Brainy
    May 17, 2021

    Thanks [mention:126a676c85024855948336691b0a7b92:e9ed411860ed4f2ba0265705b8793d05]!  The above code, as its own expression rule, has helped me out in various different Appian projects since I originally wrote it, especially those where we didn't (yet) have the RegEx plug-in.  For what it's worth, since then I've swapped it out with the actual RegEx functionality as it's able to handle a little bit more.  [mention:80250d04270e449fb1b32cc9aa5c1ef4:e9ed411860ed4f2ba0265705b8793d05] is there a reason you can't use the RegEx plug-in?

    Here's the current code (still in an expression rule i.e. `UTIL_isValidEmailAddress()`) --

    regexmatch(
      pattern: "^[A-Z0-9\_-]+(\.{0,1}[A-Z0-9\+_-]+)*[@]{1}[A-Z0-9.-]*[A-Z0-9-]+[.]{1}[A-Z]{2,6}$",
      searchString: ri!email,
      regexFlags: "si"
    )

    The Expression Guru
    davel001150
    May 17, 2021

    I'm usually the one to jump on "you're using Regex WAY too quickly" but in this case, it looks like regex is much more efficient.

    Unless Appian comes out with a "isValidEmail" function out of the box, regex may be your best bet.