PeopleCode Function To Validate Email

By Chris Malek | Wed, Nov 16, 2016

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
Author Info
Chris Malek

Chris Malek is a PeopleTools® Technical Consultant with two decades of experience working on PeopleSoft enterprise software projects. He is available for consulting engagements.

About Chris Work with Chris
Product
PeopleSoft Simple Web Services (SWS)
Do you need a quick way to create web services?

Introducing a small but powerful PeopleSoft bolt-on that makes web services very easy. If you have a SQL statement, you can turn that into a web service in PeopleSoft in a few minutes.

Book
Integration Broker - The Missing Manual

I am in the process of writing a book called "Integration Broker - The Missing Manual" that you can read online.