You need to sign in to do that
Don't have an account?
Shawn Li 9
how to count occurrence of a specific character in validation rules?
Dear Sir/Madam,
Suppose I have an input string "abc,efg,hijk", I want to count how many commas are included in the string (in this example, I want to return 2 since there are 2 commas). I searched around but found nothing. There is a similar post with no solution: https://developer.salesforce.com/forums/?id=906F0000000D8qKIAS
Thank you for the help.
Suppose I have an input string "abc,efg,hijk", I want to count how many commas are included in the string (in this example, I want to return 2 since there are 2 commas). I searched around but found nothing. There is a similar post with no solution: https://developer.salesforce.com/forums/?id=906F0000000D8qKIAS
Thank you for the help.
refer the link below:
http://stackoverflow.com/questions/863125/regular-expression-to-count-number-of-commas-in-a-string
To count the number of commas (or any specific character) in a validation rule for the text field myfield__c, you can do the following:
LEN(myfield__c)-LEN(SUBSTITUTE(myfield__c,",",""))
The SUBSTITUTE function replaces the comma characters in the field with a zero-length string. The length of the string after substitution subtracted from the original length of the string gives you the number of commas that are in the original string.
You can compare this to whatever you need for the validation rule. If there should be NO commas, then your validation rule would be:
LEN(myfield__c)-LEN(SUBSTITUTE(myfield__c,",","")) > 0