DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Nicely Format Phone Numbers in WP7

Nicely Format Phone Numbers in WP7

Jerry Nixon user avatar by
Jerry Nixon
·
Jan. 01, 12 · Mobile Zone · Interview
Like (0)
Save
Tweet
3.87K Views

Join the DZone community and get the full member experience.

Join For Free
This is a simple requirement: the user types in some string that should be a phone number. You need to format that string to look nice and neat. Assuming that we are in the United States where there are 10 digit numbers and a country code of +1, here’s the solution:

image

In the code above we remove everything that is not a number. Then we strip the country code. Then we have to handle different lengths. Only lengths of 7 and 10 are truly valid. Greater than 10, we assume it is an extension and we format it as such.

Get the code here.

The output should look something like this:

image

I hope this helps you while you are developing. Best of luck!

Source:  http://blog.jerrynixon.com/2011/12/format-phone-numbers.html

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Writing Beautiful, Optimized, and Better .NET Code With NDepend Static Analysis
  • Is DataOps the Future of the Modern Data Stack?
  • API Security Weekly: Issue 165
  • Getting Started With RSocket Kotlin

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo