1

Hello I should think of this regular expression:

The telephone number should begin with 087 OR 088 OR 089 and then it should be followed by7 digits: This is what I made but it doesn't work correctly: it accepts only numbers which begin with 089

(087)|(088)|(089)[0-9]{7}";
Tania Marinova
  • 1,788
  • 8
  • 35
  • 63

4 Answers4

2

Maybe /08[7-9][0-9]{7}/ is what you're searching for?

Autopsy:

  • 08 - a literal 08
  • [7-9] - matches the numbers from 7-9 once
  • [0-9]{7} - matches the numbers from 0-9 repeated exactly 7 times

That said, you might prefer /^08[7-9][0-9]{7}$/ if your string is only the phone number. (^ means "the string MUST start here" and $ means "the string MUST end here").

h2ooooooo
  • 37,963
  • 8
  • 65
  • 101
2
/08[789]\d{7}/

that will match 087xxxxxxx, 088xxxxxxx, 089xxxxxxx numbers.

See it in action

revo
  • 45,845
  • 14
  • 70
  • 113
0

Actually that will be far better regex for Bulgarian phone numbers:

/(\+)?(359|0)8[789]\d{1}(|-| )\d{3}(|-| )\d{3}/

It checks:

  1. Phones that start with country code(+359) or 0 instead;
  2. if the phone number use delimiters like - or space.
speedyGonzales
  • 228
  • 3
  • 12
0

I tried it in https://regex101.com and it did not work against my test set. So I tweaked it a little bit with the below regex pattern:

^([+]?359)|0?(|-| )8[789]\d{1}(|-| )\d{3}(|-| )\d{3}$
U12-Forward
  • 65,118
  • 12
  • 70
  • 89
TTS
  • 1