Solved

Regular Expression

Posted on 2011-03-19
6
252 Views
Last Modified: 2012-05-11
I do not have expirience about Reg's and i need some help
this Regular :
\((?<AreaCode>\d{3})\)\s*(?<Number>\d{3}(?:-|\s*)\d{4})

Open in new window

gives me a result like (800) 325-3535 or (210) 556 3535
i need a regular expression like +30 (210) 5563535
First part is an international code (max 9 digit plus + at the begging)
second part is area Code max 6 digit within parenthesis
third part is the actual tel number max 10 digits
0
Comment
  • 4
  • 2
6 Comments
 
LVL 8

Expert Comment

by:crysallus
ID: 35171495
This should match your current examples, as well as with the international extension added. In other words the international code is defined as optional here.

(?:(?<IntCode>\+\d{1,9}?)\s*)?\((?<AreaCode>\d{3})\)\s*(?<Number>\d{3}(?:-|\s*)\d{4})

Open in new window

If you don't want the international code to be optional, and only match numbers with the international code, then try this:

(?<IntCode>\+\d{1,9}?)\s*\((?<AreaCode>\d{3})\)\s*(?<Number>\d{3}(?:-|\s*)\d{4})

Open in new window

0
 
LVL 8

Accepted Solution

by:
crysallus earned 250 total points
ID: 35171512
oops. Forgot about the other changes you mentioned in points 2 and 3. Try this, for optional international code:

(?:\+(?<IntCode>\d{1,9}?)\s*)?\((?<AreaCode>\d{1,6})\)\s*(?<Number>\d{1,10})

Open in new window

Not optional:

\+(?<IntCode>\d{1,9}?)\s*\((?<AreaCode>\d{1,6})\)\s*(?<Number>\d{1,10})

Open in new window

0
 
LVL 18

Author Comment

by:John (Yiannis) Toutountzoglou
ID: 35171521
You got it in your second post ...
thank you very much ....
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 18

Author Comment

by:John (Yiannis) Toutountzoglou
ID: 35171598
i try to inert a specified Set of [0-9] to accept only numbers and it Match also if with letter...
"Your Syntax is correct.." ..i try this
\+(?<IntCode>\d{1,9}?[0-9])\s*\((?<AreaCode>\d{1,6}?[0-9])\)\s*(?<Number>\d{1,10}?[0-9])

Open in new window

What am i missing?
0
 
LVL 18

Author Comment

by:John (Yiannis) Toutountzoglou
ID: 35171832
For example if i set +30 (210) 5564fffff then it return true....
0
 
LVL 18

Author Comment

by:John (Yiannis) Toutountzoglou
ID: 35171836
My expression is
\+(?<IntCode>\d{1,9}?)\s*\((?<AreaCode>\d{1,6})\)\s*(?<Number>\d{1,10})

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question