Phone Regular Expression Check for Argentina

I understood the regex for my phone in the country, but I have something missing.

The rule is here: (Area Code) Prefix - Sufix

  • Area code can be 3 to 5 digits
  • The prefix can contain from 2 to 4 digits.
  • Zone code + 7-digit prefix.
  • The suffix is ​​always 4 digits long
  • Total numbers: 11.

I decided that I could have 3 simple regular expressions with OR "|" eg:

/(\(?\d{3}\)?[- .]?\d{4}[- .]?\d\d\d\d)|(\(?\d{4}\)?[- .]?\d{3}[- .]?\d\d\d\d)|(\(?\d{5}\)?[- .]?\d{2}[- .]?\d\d\d\d)/

What I'm doing wrong is that \d\d\d\donly 4 digits do not match for sufix, for example: (011) 4740-5000, which is a valid phone number, works fine, but if you add extra digits, it will also return as a valid number phone, i.e.: (011) 4740-5000000000

+4
5

^ $

^\d{4}$ 4 .

^((\(?\d{3}\)? \d{4})|(\(?\d{4}\)? \d{3})|(\(?\d{5}\)? \d{2}))-\d{4}$

-


-, . ,

^((\(?\d{3}\)?[-. ]?\d{4})|(\(?\d{4}\)?[-. ]?\d{3})|(\(?\d{5}\)?[-. ]?\d{2}))[-. ]?\d{4}$
+1

:

/^\\(?(\d{3,5})?\\)?\s?(15)?[\s|-]?(4)\d{2,3}[\s|-]?\d{4}$/
+1

complete, . .

/^(?=(\D*\d){11}$)\(?\d{3,5}\)?[- .]?\d{2,4}[- .]?\d{4}$/

:

(?=(\D*\d){11}$)    is a non-capturing group ensuring that there are 11 digits total,
                     with any number of non-digits amongst them
\(?\d{3,5}\)?[- .]? matches 3-5 digits in parens (area code), followed by a separator
\d{2,4}[- .]?       matches 2-4 digits (prefix), followed by a separator
\d{4}               matches the suffix
0

regex101:

/^((?:\(?\d{3}\)?[- .]?\d{4}|\(?\d{4}\)?[- .]?\d{3}|\(?\d{5}\)?[- .]?\d{2})[- .]?\d{4})$/

- RegEx

  • ^
    • (
      • (?: ,
      • )
      • [- .]?\d{4} The last four digits of a phone number
    • ) End Recording Group
  • $ Matches end of line
0
source

If you are trying to verify such a phone number, then the following should meet your needs:

^(?=.{15}$)[(]\d{3,5}[)] \d{2,4}-\d{4}$

Regular expression visualization

Demo version of Debuggex

0
source

All Articles