Click here to Skip to main content
15,887,386 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My page contains national and international phone numbers.I want to replace the only the country code part with blank space.
So can you help me whether i should use any regular expression or c# code to replace country code ?

Thanks in advance.
Posted
Comments
S@53K^S 23-Apr-12 10:48am    
Obviously you'll use regular expression to find out the country code from the phone number.

Start here[^] - good source of regular expressions.
 
Share this answer
 
Comments
akee seth 23-Apr-12 12:08pm    
But i want to get the country code from phone number or whether it contains country code or not.
for ex: (123)456-6789(does not contain country code)
(or) +1-123-456-6789(contain country code)
R. Giskard Reventlov 23-Apr-12 12:16pm    
That's the bit you have to work out for yourself: I've given you a site that will help with regular expressions: not you just have to figure out how to apply them. You won't learn if someone else does it for you.
Hi all,

I became little bit messy here.
I want to search details of employee through phone number.So when i search though it contain country code or not gave the same result.

Thanks.
 
Share this answer
 
Replace the country code with blank space-

phoneNumber = Regex.Replace(phoneNumber, "\\+[0-9]{1,}", "");

ex:+12-122-456-3245
You get -122-456-3245
 
Share this answer
 
Comments
GarthJones 18-Feb-20 18:16pm    
You are assuming there is a - after the country code which you cannot assume.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900