Validate a DVA File number using a regular expression

Posted on
regex dva medicare

I’ve been working on DVA (Australia’s Department of Veterans' Affairs) number validation recently and couldn’t find a working regular expression.

This post by (I think) Mike Squires has the basics right but this expression can’t handle the space as the War code. It also isn’t handling the last optional letter for dependents.

So I came up with the updated version:

/^([NVQWST]{1})(([A-Z\s]{1}\d{1,6})|([A-Z]{2}\d{1,5})|([A-Z]{3}\d{1,4}))([A-Z]{0,1})$/i

I’m a n00b with regex but I think this one is pretty close (associated with a length 3 to 9 check on the string, of course)

Hit me on twitter if you know of a better way!