Human Capital Management Blogs by Members
Gain valuable knowledge and tips on SAP SuccessFactors and human capital management from member blog posts. Share your HCM insights with a post of your own.
cancel
Showing results for 
Search instead for 
Did you mean: 
Karthi_Viswa
Active Contributor
Hello All,

In this blog am going to explain how a simple and powerful Regular Expression can be used to Validate email address field on Contact Info Portlet.

Requirement 1: Email address field should mandate with "@" symbol and should have ". (dot)" at any place after @ symbol and can end with any type of domain.

Example: sap@sap.uk or sap@sap.edu or sap@sap.com

Regular Expression: ^[\w-\.]+@([\w-]+\.)+[\w-]{2,3}$


Below is the explanation for the above to be configured regular expression. we are going to use it on rule to validate email address.

^ Beginning. Beginning of the line.

[ Character Set. Match any character in the set.


\w word. Matches any word character (alphanumeric & underscore).


-  Character. Matches a "-" character


\. Escaped character. Matches a "." character


] close character set


+ Quantifier. Match 1 or more of the preceding character or token

@ Character. Matches a "@" character.


(  Capturing groups. opens a capture group


) Capturing groups. closes a capture group


{2,3} Quantifier. Match between 2 and 3 of the preceding character or token


$ End. End of the line.

Now that we got a fair idea of those expressions, let us see how we can configure above expression to a rule to validate email address.

Create a "IF" condition with "Matches" function like below and have an error message to "Then" condition


Attach the above rule to OnChange - Email address field and OnSave - Email Address Portlet.




Requirement 2: Email address field should mandate with "@" symbol and should end with ".COM" only.

Example: sap@sap.com (Note: should accept only .com)

Regular Expression: ^[\w-\.]+@([\w-]+\.[com]{3})$








Requirement 3: Email address field should mandate with "@" symbol and should end with particular domain Only.

Example: sap@karthik.com  (should end with @karthik.com only.)

Regular Expression: ^[\w-\.]+@([karthik]{7}+\.[com]{3})$



 

Regular Expression is a very simple and a powerful expression which can be used in many ways for these kind of validations, it can be used over any string field for character set validations also.

To check for duplicate email, check below blog,


https://blogs.sap.com/2021/03/08/checking-for-duplicate-email-business-and-personal-successfactor-em...

Keep Exploring. Thanks for reading.

 
6 Comments
Labels in this area