Solved

Regular Expression

Posted on 2011-03-19
6
240 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now