Human Capital Management Blogs by Members
Gain valuable knowledge and tips on SAP SuccessFactors HCM suite and human capital management market from member blog posts. Share your insights with a post of your own.
cancel
Showing results for 
Search instead for 
Did you mean: 
Karthi_Viswa
Active Contributor
12,612
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.

 
7 Comments

Hi Karthik,

 

Very Useful info. Thank you very much.

 

I would liek to add one more expression, for domains like: sap@bestrun-sap.de

 

Regular Expression: ^[\w-\.]+@([bestrun]{7}+\-[sap]{3}+\.[de]{2})$

 

 

I have seen couple of customers asking for this kind of expressions.

 

I hope this would helpful.

 

Thank you!

 

Best Regards,

ck

om_awasthi1
Participant
Hi Karthik,

 

That's a amazing piece of blog you wrote. I was trying to achieve the last example which you have shared.

 

Thank you,

Om
Karthi_Viswa
Active Contributor
0 Kudos
Thank you, Good to hear that it helped to achieve one of your requirement,
Karthi_Viswa
Active Contributor
Thanks for sharing CK, we can play with regular expression to achieve many more validations like this.

Thank you.
ddeendyal
Explorer
0 Kudos
Hi Karthik,

 

I'm trying to achieve enforcing a 24 hour format on a custom field on the Job Information portlet. Not sure how this can be achieved via the regular expression. Your thoughts ?

Regards

Divya
0 Kudos
Hi Karthik

 

Can you let me know how did you use this regex in your code. I am quite new to this and thus am not able to figure this part out.

 

Thanks

Sulagna Chakraborty
IWS
Explorer
0 Kudos

Hi,

In our company we have different email extensions, for example snop.eu, but also balconi.it and we have some others.

If I set up a rule with @snop.eu only or balconi.it only, then it works, but if I combine them (see printscreen), then it does not work anymore (then it raises a message when I enter a business email with @snop.eu as extension):

BusinessEmail_Error.png

Why is that?

Thanks,

Ilse Wullaert | HRIS SF Employee Central & Performance Specialist

 

Labels in this area