By | 16 November 2016

PeopleCode Function To Validate Email

This function uses a REGEX to validate an email pattern. The java REGEX came from emailregex.com.

Function IsValidEmailPattern(&emailIn As string) Returns boolean

   Local JavaObject &jCheckEmailRegex;
   Local JavaObject &jInput;

   /* source http://emailregex.com */

   Local string &regexString;

   &regexString = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|";
   &regexString = &regexString | Char(34);

   &regexString = &regexString | "(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*";
   &regexString = &regexString | Char(34);
   &regexString = &regexString | ")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])";

   &jCheckEmailRegex = CreateJavaObject("java.lang.String", &regexString);
   &jInput = CreateJavaObject("java.lang.String", lower(&emailIn));

   If &jInput.matches(&jCheckEmailRegex) Then
      Return True;
   Else
      Return False;
   End-If;

End-Function;

Article Categories

Do you want to become a CI Expert?

If you want to learn more about developing using Component Interface then check out our CI Training Video.