Quantcast
Viewing all articles
Browse latest Browse all 224

regular expression to find tax file numbers

Hi all,

I'm new to regular expressions and what I want to do seems a bit advanced for me.

I'd like to create a regular expression to locate valid Australian tax file numbers.

Here's the regular expression I've come up with so far:
(\d{8,9})|(\d\d\d[ ]\d\d\d[ ]\d\d\d)|(\d\d\d[-]\d\d\d[-]\d\d\d)

Tax file numbers can be either 8 or 9 digits and this string successfully finds them, however, it also picks up numbers like mobile phone numbers.
I also tried to incorporate a few different ways people generally type out tax file numbers which is why I've added in a - and also white space.

There is a formula to detect if a tax file number is valid and this is what id like to add to the string to remove the false positives.

From wikipedia:
Tax file number - Wikipedia[^]

As is the case with many identification numbers, the TFN includes a check digit for detecting erroneous numbers. The algorithm is based on simple modulo 11 arithmetic per many other digit checksum schemes.

Example[edit]
The validity of the example TFN '123456782' can be checked by the following process

The sum of the numbers is 253 (1 + 8 + 9 + 28 + 25 + 48 + 42 + 72 + 20 = 253). 253 is a multiple of 11 (11 × 23 = 253). Therefore, the number is valid.

Can it be done?
Can someone assist?

Viewing all articles
Browse latest Browse all 224

Trending Articles