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
Akshay MenseAkshay Mense 

can we use validation rule for a field to accept the only the values of particular data types based on the picklist selection

Hi Team, 

I have a scenario where i want the field to accet the value of data type for e.g. if i select percentage in picklist then it should only accept percentage value. if i select numeric it should accept only numeric values. and this field should be required if the picklist is not blank. How  can we achieve this? can we use validation rules here. if yes. can you help me with it. 
Best Answer chosen by Akshay Mense
AnudeepAnudeep (Salesforce Developers) 
Yes, you can use REGEX in your validation rule to achieve this. You should write your validation rule in such a way that it will allow only numbers, decimal and % symbol.

An example is 
 
!REGEX(Text_Field__c, "[0-9]{1,3}(\\.[0-9]{1,2})?%?") || 
    IF(RIGHT(Text_Field__c,1) = "%", 
        VALUE(LEFT(Text_Field__c,LEN(Text_Field__c)-1)) > 100, 
        VALUE(Text_Field__c) > 100)

I recommend looking at the common REGEX validations for examples

If you find this information helpful, please mark this answer as Best. It may help others in the community. Thank You!