I'm trying to build a regex to verify in JS if a international number is well formated.
I consider a number is formated as follow : '00'[country][number]. The 'country' and the 'number' are simply numbers (which can't start with 0). The 'country' have size {1-3}, and the 'country' + 'number' are < 15.
I use this wrong regex : /^00[1-9][0-9]{0,2}[1-9][0-9]{0,11}$/ My problem is about the size of 'number' that depend of 'country' size. The max size of 'number' is 15-'country'.size
How can I do that ?
I see What regular expression will match valid international phone numbers? but number size is fixed to 15, not depending on country size. And a generic way (not giving all the countries codes) should be better, if possible.
Here some example that have to match with the regex
- 00111111111111111
- 001100
- 00111111111111111
- 00100100000000000
- 00101000000000000 (my regex do not match it, because in this case 'country' = 2 and 'number' = 13)
and not to match with
- 00100010000000000 ('country' = 4)
Thx a lot