Skip to main content
Brian LaRue が「#Data Management」で質問
I am trying to implement a validation rule on a custom field on a Contact. I would like to permit the field to be either blank or a number between one and seven.

 

The data type of the custom field is Text(1).

 

 

ISBLANK('Custom_Field__c') || REGEX(Custom_Field__c, '[1-7]')

 

This formula will allow blank fields. Great 50% there. Although, it will also permits a number outside the desired range AND alpha characters. What gives? What am I doing wrong?

 

Thank you Salesforce Community, you're my only hope!
5 件の回答
  1. 2019年3月28日 20:09
    Yes, all data in that field is currently valid. Up until now it was previously only populated by Apex. We've recently been given a requirement to allow editing of that field. Therefore, I'm trying to futureproof POBCAK errors. 

     

    I like the idea of changing datatype but that field is referenced in triggers, apex classes, and apex test classes. That would take some retoolilng to dereference, make the change, then rereference in code--all for a pesky formula. oh_how_i_love_sfdc.jpg

     

    I have tried, with a little modificaiton from your suggestion, the following formula:

    NOT(ISBLANK(Custom_Field__c))

    &&

    NOT(ISNUMBER(Custom_Field__c) || VALUE(Custom_Field__c) < 1 || VALUE(Custom_Field__c) > 7)

     

    It still let me save an 'a' as well as a '9' in the field. SMH. ¯\_(ツ)_/¯
0/9000