Replace non-numeric with empty string

Definitely regex: string CleanPhone(string phone) { Regex digitsOnly = new Regex(@”[^\d]”); return digitsOnly.Replace(phone, “”); } or within a class to avoid re-creating the regex all the time: private static Regex digitsOnly = new Regex(@”[^\d]”); public static string CleanPhone(string phone) { return digitsOnly.Replace(phone, “”); } Depending on your real-world inputs, you may want some additional logic … Read more

How do I get the dialer to open with phone number displayed?

Two ways to achieve it. 1) Need to start the dialer via code, without user interaction. You need Action_Dial, use below code it will open Dialer with number specified Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse(“tel:0123456789”)); startActivity(intent); The ‘tel:’ prefix is required, otherwhise the following exception will be thrown: java.lang.IllegalStateException: Could not execute method of the … Read more

What’s the longest possible worldwide phone number I should consider in SQL varchar(length) for phone

Assuming you don’t store things like the ‘+’, ‘()’, ‘-‘, spaces and what-have-yous (and why would you, they are presentational concerns which would vary based on local customs and the network distributions anyways), the ITU-T recommendation E.164 for the international telephone network (which most national networks are connected via) specifies that the entire number (including … Read more

Programmatically get own phone number in iOS

At the risk of getting negative marks, I want to suggest that the highest ranking solution (currently the first response) violates the latest SDK Agreement as of Nov 5, 2009. Our application was just rejected for using it. Here’s the response from Apple: “For security reasons, iPhone OS restricts an application (including its preferences and … Read more

Programmatically obtain the phone number of the Android phone

Code: TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE); String mPhoneNumber = tMgr.getLine1Number(); Required Permission: <uses-permission android:name=”android.permission.READ_PHONE_STATE”/> Caveats: According to the highly upvoted comments, there are a few caveats to be aware of. This can return null or “” or even “???????”, and it can return a stale phone number that is no longer valid. If you want something … Read more

tech