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
))

Comments

  1. Looks like a great validation rule and I have to admit I tested it as working. However I fail to see what this is actually doing. Could you explain in further detail? Otherwise great post and thanks for sharing!

    ReplyDelete
  2. I've updated the original post to include a link to the "Format of the ABN" page from the government: https://www.ato.gov.au/Business/Australian-business-number/In-detail/Introduction/Format-of-the-ABN/

    ReplyDelete
  3. OK, that's great & once again thank you for sharing!

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Hi San,

    The idea with the formula is that there are no spaces in the ABN. Removing those first parts breaks that checking.

    ReplyDelete
  8. IF(

    MOD(
    10 * ((VALUE(MID(SUBSTITUTE(ABN__c, ' ', ''), 1, 1)))-1) +
    1 * VALUE(MID(SUBSTITUTE(ABN__c, ' ', ''), 2, 1)) +
    3 * VALUE(MID(SUBSTITUTE(ABN__c, ' ', ''), 3, 1)) +
    5 * VALUE(MID(SUBSTITUTE(ABN__c, ' ', ''), 4, 1)) +
    7 * VALUE(MID(SUBSTITUTE(ABN__c, ' ', ''), 5, 1)) +
    9 * VALUE(MID(SUBSTITUTE(ABN__c, ' ', ''), 6, 1)) +
    11 * VALUE(MID(SUBSTITUTE(ABN__c, ' ', ''), 7, 1)) +
    13 * VALUE(MID(SUBSTITUTE(ABN__c, ' ', ''), 8, 1)) +
    15 * VALUE(MID(SUBSTITUTE(ABN__c, ' ', ''), 9, 1))+
    17 * VALUE(MID(SUBSTITUTE(ABN__c, ' ', ''), 10, 1))+
    19 * VALUE(MID(SUBSTITUTE(ABN__c, ' ', ''), 11, 1))

    ,89) <> 0,
    TRUE,FALSE)

    ReplyDelete
  9. Thanks Fosnez. Just pasted my formula which refers a Text field with spaces in ABN format.

    ReplyDelete

Post a Comment

Popular posts from this blog

Salesforce Merge Accounts URL Hacking

Australian Postcode Boundaries for Google Earth (KMZ)

Don't look up!