-2

I need to validate a VAT number (9 digits long) which has the following validation scheme.

Let's assume that 9 digits as d1 d2 d3 d4 d5 d6 d7 d8 d9 where :

(d1*256 + d2*128 + d3*64 + d4*32 + d5*16 + d6*8 + d7*4 + d8*2) / 11 = d9

all the above sum divided by 11 equals d9.

Is it possible to validate this VAT number with a Regular Expression and if yes how?

gp_sflover
  • 3,460
  • 5
  • 38
  • 48
vlaxos
  • 7
  • 3
    which programming language are you using ? IMHO, you'd be better of validating this with JavaScript on the front-end and your back-end language. You're computing values, not pattern matching. – Sumi Straessle Jul 23 '17 at 09:22
  • Just curious -- which country uses that scheme? *Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems.* -- *Jamie Zawinski* – Ron Rosenfeld Jul 23 '17 at 20:41

1 Answers1

0

It might be possible to do this with regex. I've seen some wild things that you can do with Regex (e.g. Is it possible to increment numbers using regex substitution?).

However this is probably always a bad idea. It is much easier (and much more readable) to just convert the numbers to integers and do the check with your favorite programming language instead.

Jakube
  • 3,353
  • 3
  • 23
  • 40