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
))
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!
ReplyDeleteI'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/
ReplyDeleteOK, that's great & once again thank you for sharing!
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHi San,
ReplyDeleteThe idea with the formula is that there are no spaces in the ABN. Removing those first parts breaks that checking.
IF(
ReplyDeleteMOD(
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)
Thanks Fosnez. Just pasted my formula which refers a Text field with spaces in ABN format.
ReplyDelete