function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rick MacGuiganRick MacGuigan 

Validation for multiple ranges

How would I validate the following

User enters a credit agency from a picklist and enters a numerical score. Validate that the score entered is within the range associated with the credit agency.
For example, range for equifax is 300-850, experian is 330-830. User selects experian and enters 310 which is outside the range for experian.

In total I have 5 credit agencies . Only one credit score value is entered.
 
Best Answer chosen by Rick MacGuigan
Venkat PolisettiVenkat Polisetti
Try this:

(TEXT(Credit_Agency__c) = "Equifax" && (Score__c < 300 || Score__c > 850)) 
||
(TEXT(Credit_Agency__c) = "Experian" && (Score__c < 330 || Score__c > 830))

Thanks,
Venkat

All Answers

Geoffrey J FlynnGeoffrey J Flynn
I think this is how I would try it first:
OR(
ISPICKVAL(credit__2, "Equifax") && score__c <300,
ISPICKVAL(credit__2, "Equifax") && score__c >850,
ISPICKVAL(credit__2, "Experian") && score__c <330,
ISPICKVAL(credit__2, "Experian") && score__c >830,
*and so on
)

If it was a large number (more than 5), I would probably be doing it with a lookup instead of a picklist and store the upper and lower bounds against an Equifax record for example.  You could run validation off of that much easier.  With 5 though this is probably fine.
Venkat PolisettiVenkat Polisetti
Try this:

(TEXT(Credit_Agency__c) = "Equifax" && (Score__c < 300 || Score__c > 850)) 
||
(TEXT(Credit_Agency__c) = "Experian" && (Score__c < 330 || Score__c > 830))

Thanks,
Venkat
This was selected as the best answer
Rick MacGuiganRick MacGuigan
Geoffrey and Venkat, thanks. both work well. Appreciate your responses.