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:
• 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:
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:
• Only alphabetic character can be entered in a sting field. Populate the Business Rules as follows:
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:
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
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