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
Sarah WiensSarah Wiens 

Validation rule help: modifying to allow for empty field

I'm setting up a custom "Graduating Class" field for our contacts. I want users to either leave the field blank or enter numbers in the field in the YYYY format (no commas). How do you recommend I write the validation rule?

So far I have NOT(ISNUMBER( Graduating_Class__c )) to strip the comma, but I'm not sure how to modify to allow for a blank option.
Best Answer chosen by Sarah Wiens
Footprints on the MoonFootprints on the Moon
Hey Sarah,
You can have Graduating_Class__c  as Text of lenght 4, and have below Validation rule set on Contact-
NOT ( ISBLANK ( Graduating_Class__c ) )
&&
(
NOT ( ISNUMBER ( Graduating_Class__c ) )
||
LEN ( Graduating_Class__c ) < 4
)
Here, we are checking that Graduating_Class__c must be a number and of length 4, if it is entered. Otherwise no error.
Let me know if this helps!

All Answers

Footprints on the MoonFootprints on the Moon
Hey Sarah,
You can have Graduating_Class__c  as Text of lenght 4, and have below Validation rule set on Contact-
NOT ( ISBLANK ( Graduating_Class__c ) )
&&
(
NOT ( ISNUMBER ( Graduating_Class__c ) )
||
LEN ( Graduating_Class__c ) < 4
)
Here, we are checking that Graduating_Class__c must be a number and of length 4, if it is entered. Otherwise no error.
Let me know if this helps!
This was selected as the best answer
Sarah WiensSarah Wiens
Thank you so much, this works great!