Skip to Content
Technical Articles
Author's profile photo Karthik Viswanathan

Validate Email Address with Regular Expression – SuccessFactor Employee Central

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-employee-central/

Keep Exploring. Thanks for reading.

 

Assigned tags

      6 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Chiranjeevi Kata
      Chiranjeevi Kata

      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

      Author's profile photo Karthik Viswanathan
      Karthik Viswanathan
      Blog Post Author

      Thanks for sharing CK, we can play with regular expression to achieve many more validations like this.

      Thank you.

      Author's profile photo Om Awasthi
      Om Awasthi

      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

      Author's profile photo Karthik Viswanathan
      Karthik Viswanathan
      Blog Post Author

      Thank you, Good to hear that it helped to achieve one of your requirement,

      Author's profile photo Divya Deendyal
      Divya Deendyal

      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

      Author's profile photo sulagna Chakraborty
      sulagna Chakraborty

      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