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
Rahul Kumar DeyRahul Kumar Dey 

Validation Rule help- A custom field need to be 14 character length including space break. If Custom field not capturing space break then it should be 11 character length.

Hey guys, 

I try to create a validation rule where custom field ABN__c should be 14 character length if there are any spaces but if there is no space then it should be 11 characters length.

my validation as of now -
AND(NOT(ISBLANK(ABN__c)),
OR(LEN(ABN__c) != 14,
 AND(  NOT(REGEX( ABN__c,'[a-zA-Z-0-9- ]'))  ,LEN(ABN__c) != 11) )
)

Thanks in advance
Rahul:)
Best Answer chosen by Rahul Kumar Dey
Sowjanya Hegde 13Sowjanya Hegde 13
Hi Rahul,

Instead of REGEX you can use CONTAINS  to check whether the field contains space or not.

AND(
NOT(ISBLANK(ABN__c)),
OR(
AND(CONTAINS(ABN__c , ' '),LEN(ABN__c) != 14),
AND(NOT(CONTAINS(ABN__c , ' ')) ,LEN(ABN__c) != 11
) ) )

Thank you!

All Answers

Sowjanya Hegde 13Sowjanya Hegde 13
Hi Rahul,

Instead of REGEX you can use CONTAINS  to check whether the field contains space or not.

AND(
NOT(ISBLANK(ABN__c)),
OR(
AND(CONTAINS(ABN__c , ' '),LEN(ABN__c) != 14),
AND(NOT(CONTAINS(ABN__c , ' ')) ,LEN(ABN__c) != 11
) ) )

Thank you!
This was selected as the best answer
Rahul Kumar DeyRahul Kumar Dey
@Sowjanya, thanks it's working as expected.

Thank You,
Rahul:)