phone number should be a string or some numeric type that have capacity to save phone number?

ITU-T recommendation E.164 says you need 3 digits for the country code and up to 15 digits for the directory number within the country dialing plan. And, many people add some punctuation. For example: +1.212.555.1212 is a North American number. It could also be rendered (212) 555-1212 in a North American centric app. 32 characters … Read more

Android get all contacts telephone number in ArrayList

ContentResolver cr = mContext.getContentResolver(); //Activity/Application android.content.Context Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); if(cursor.moveToFirst()) { ArrayList<String> alContacts = new ArrayList<String>(); do { String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); if(Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) { Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +” = ?”,new String[]{ id }, null); while (pCur.moveToNext()) { String contactNumber = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); alContacts.add(contactNumber); break; } pCur.close(); } } … Read more

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

Phone number validation Android

Use isGlobalPhoneNumber() method of PhoneNumberUtils to detect whether a number is valid phone number or not. Example System.out.println(“….g1…”+PhoneNumberUtils.isGlobalPhoneNumber(“+912012185234”)); System.out.println(“….g2…”+PhoneNumberUtils.isGlobalPhoneNumber(“120121852f4”)); The result of first print statement is true while the result of second is false because the second phone number contains f.

Which is best data type for phone number in MySQL and what should Java type mapping for it be?

Strings & VARCHAR. Do not try storing phone numbers as actual numbers. it will ruin the formatting, remove preceding 0s and other undesirable things. You may, if you choose to, restrict user inputs to just numeric values but even in that case, keep your backing persisted data as characters/strings and not numbers. Be aware of … Read more

Mask US phone number string with JavaScript

This answer assumes you want the following format: (000) 000-0000 (as the OP states). There are multiple different ways to implement this, but here are a couple different approaches: If you want to simply mask the number on the blur event (when the field loses focus), then you could use the following: document.getElementById(‘phone’).addEventListener(‘blur’, function (e) … Read more

Android: Retrieve contact name from phone number

Although this has already been answered, but here is the complete function to get the contact name from number. Hope it will help others: public static String getContactName(Context context, String phoneNumber) { ContentResolver cr = context.getContentResolver(); Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); Cursor cursor = cr.query(uri, new String[]{PhoneLookup.DISPLAY_NAME}, null, null, null); if (cursor == null) { … Read more