1

I need to check numbers, national and international with the same Regex. I receive numbers on 33ZABPQMCDU and 0ZABPQMCDU formats.

The regex have to accept on 33ZABPQMCDU and 0ZABPQMCDU formats, but refuse numbers on 3389BPQMCDU and 089BPQMCDU formats.

For example

OK :

0545904660

33545904660

KO :

0895904660

33895904660

I don't know how to verify that a number is well constructed, and on the same time to reject numbers beginning with 089 or 3389.

Thanks

bartmaul
  • 23
  • 4

1 Answers1

0

You have to use a negative lookahead assertion.

(?!^089\d{7}$)

excludes 10-digit numbers starting with "089." Here:

/(?!^089\d{7}$)(?!^3389\d{7}$)^(\d{10}\d?)$/

Also see RegEx to exclude a specific string constant

Community
  • 1
  • 1
La-comadreja
  • 5,627
  • 11
  • 36
  • 64