Tuesday, June 10, 2014

Australian Business Number (ABN) Validation Rule for Salesforce.com

Assuming your Custom field is "ABN" (API Name = "ABN__c") then you can stuff this formula in a validation rule to ensure that ABNs entered are valid by using the same logic the government does.

not(and
(
  LEN(TRIM( ABN__c )) == 11,
  ISNUMBER(ABN__c),
  mod( 
     (((VALUE(MID(ABN__c, 1, 1)) - 1 ) * 10) + 
(VALUE(MID(ABN__c, 2, 1)) * 1) + 
(VALUE(MID(ABN__c, 3, 1)) * 3) + 
(VALUE(MID(ABN__c, 4, 1)) * 5) + 
(VALUE(MID(ABN__c, 5, 1)) * 7) + 
(VALUE(MID(ABN__c, 6, 1)) * 9) + 
(VALUE(MID(ABN__c, 7, 1)) * 11) + 
(VALUE(MID(ABN__c, 8, 1)) * 13) + 
(VALUE(MID(ABN__c, 9, 1)) * 15) + 
(VALUE(MID(ABN__c, 10, 1)) * 17) + 
(VALUE(MID(ABN__c, 11, 1)) * 19)),
89
  ) == 0
))