B
B
Big_Trouble2021-09-13 17:18:52
Regular Expressions
Big_Trouble, 2021-09-13 17:18:52

How to fix regular expression for phone number search?

I'm not very good with regular expressions. Found this on google

'^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$'

but it skips expressions like: 0000-0000 and 00-00-00 tell me how to fix it so that only such ones are skipped:
+79261234567
89261234567
79261234 567
+380 123 45 67
38(026 ) 123-45-67
9261234567
79261234 ) 123 45 67 89261234567 8-926-123-45-67 8 927 1234 234 8 927 12 12 888 8 927 12 555 12 8 927 123 8 123

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Slava Rozhnev, 2021-09-13
@Big_Trouble

Use the libphonenumber library , it is adapted for many
C# programming languages: https://github.com/twcclegg/libphonenumber-csharp
Go: https://github.com/nyaruka/phonenumbers
Objective-c: https://github.com/ iziz/libPhoneNumber-iOS
PHP: https://github.com/giggsey/libphonenumber-for-php
PostgreSQL in-database types: https://github.com/blm768/pg-libphonenumber
Python: https://github.com /daviddrysdale/python-phonenumbers
Ruby: https://github.com/mobi/telephone_number
Rust: https://github.com/1aim/rust-phonenumber
Erlang:https://github.com/marinakr/libphonenumber_erlang
Clojure: https://github.com/randomseed-io/phone-number
R: https://github.com/socialresearchcentre/dialr/

S
Saboteur, 2021-09-13
@saboteur_kiev

Regulars are not conditional operators. This is a complicated, but a template, and it’s not at all a fact that all your Wishlist can be solved with one regular expression. Especially since you're in a mess here. It can start with a number and with a bracket and with a plus sign, and inside there can be spaces and hyphens and brackets, and the number of digits is different.
If it's bad with regular expressions, do without it at all, or do a few if / else with simpler regular expressions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question