Regex pattern format for austrian numbers

103 Views Asked by At

Here is what i have right now.

(\d{4,12}\/*(\+43)* *(\([0-9]+\))*([ ]*(-|–)*[ ]*[0-9]+))

or

([\/ \-\d]*)

Allowed:

03852 4637
03852 463728
03852/4637
038524637
03852463728
03852/463728
004338524637
+4338524637
00433852463728
+433852463728
00433852/4637
+4303852/4637
00433852/463728
+433852/463728

01 23457
0123457
01/23457
0043123457

+43 662 8180-0
0662 8180-0
0662 81800
066281800
0662 8180
06628180
0043662 818
00436628180
+43662 8180

Not Allowed:

122
133
144
121
911
112
110

Phone Number can be in between sentences and should match as "Match 1"

([\/ \-\d]*)

Matches with the allowed numbers but ignores the "+"

1

There are 1 best solutions below

0
On

You can use

^(?!\d{1,6}$)(?:(?:\+43|00?) ?)\d+(?:[ \/–-]\d+)*$

See the regex demo.

Details:

  • ^ - start of string
  • (?!\d{1,6}$) - the string cannot consist of just one to six digits
  • (?:(?:\+43|00?) ?) - a sequence of +43, 00 or 0 and then an optional space
  • \d+ - one or more digits
  • (?:[ \/–-]\d+)* - zero or more repetitions of a space/slash, em-dash or hyphen and then one or more digits
  • $ - end of string.