SAP Knowledge Base Article - Public

2426526 - How to use a Business Rule to apply a Format/Regular Expression to a Field

Symptom

How can I set up a business rule, to apply a format/regular expression to a field within EC.
For example:

  • only digits can be entered in a string field.
  • only alphabetic character can be entered in a sting field.
  • only latin characters can be entered into a string field
  • only a certain format can be enter, for example, 1 alphabetic character, followed be 4 digits.

Cause

This can be done using an MDF Business rule.

Resolution

The below examples, apply the above formats to the "phone-number" field in the "phoneInfo" Element.
The rules are  triggered as event type "onSave" on the"phoneInfo" Element.
These examples can be amend to meet your criteria.

• Please create a raise message with the desired error message text. You can create a different Message Definition
            >Manage Data > Create New: MessageDefinition:
  1.png

• Create a New Business rule with the desired Base Object, in this case "Phone Information".

Only digits can be entered in a string field. Populate the Business Rules as follows: 
   1.png
  The ‘IF’ condition, uses the ‘Matches()’ function to check if the phone number entered, matches the defined format.
  The format is defined as any number, which contains only digits, which has a length of 1 and 20. You can adjust the length to suit your needs, for example 1 to 10 would be "\d{1,10}".
  (\d = a digit and {1,20} = of length 1 - 20)

• Saved Rule:
   2.png

Only alphabetic character can be entered in a sting field. Populate the Business Rules as follows: 
   3.png
   The ‘IF’ condition, uses the ‘Matches()’ function to check if the phone number entered, matches the defined format.
   The format is defined as any alphabetical character, (either Upper or Lower Case), which has a length of 1 and 20. You can adjust the length to suit your needs, for example 1 to 10 would be  "[A-Za-z]{1,10}".
   ([A-Za-z]= an alphabetic character (upper or lower case) and {1,20} = of length 1 - 20)

 

Only latin characters can be entered into a string field

Please refer to article 2557647 - How to create a Business Rule to enforce the use of Latin characters only

 

Only a certain format can be enter, for example, 1 alphabetic character, followed be 4 digits. Populate the Business Rules as follows: 
  4.png
  The ‘IF’ condition, uses the ‘Matches()’ function to check if the phone number entered, matches the defined format.
  The format is defined as any 1 alphabetical character, (either Upper or Lower Case), followed by exactly 4 digits.

See Also

  • 2092849 - How to create a Business Rule to validate data on change/save, and provide a Warning or Error message
  • 2421885 - How to Validate that Only Digits are Entered in the Phone Number Field
  • 2557647 - How to create a Business Rule to enforce the use of Latin characters only

Keywords

Format, Business Rule, Regular Expression, Number, Digit, Alphanumeric, reg-ex, Matches(), Format(), Matches, String to be checked , KBA , LOD-SF-EC , Employee Central , LOD-SF-MDF-RUL , Custom Oject based Business Rules , How To

Product

SAP SuccessFactors Employee Central all versions