Remove dash from a phone number

phoneNumber.replaceAll(“[\\s\\-()]”, “”); The regular expression defines a character class consisting of any whitespace character (\s, which is escaped as \\s because we’re passing in a String), a dash (escaped because a dash means something special in the context of character classes), and parentheses. See String.replaceAll(String, String). EDIT Per gunslinger47: phoneNumber.replaceAll(“\\D”, “”); Replaces any non-digit with … Read more

How to get the mobile number of current sim card in real device?

You can use the TelephonyManager to do this: TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); String number = tm.getLine1Number(); The documentation for getLine1Number() says this method will return null if the number is “unavailable”, but it does not say when the number might be unavailable. You’ll need to give your application permission to make this query by adding … Read more

RegEx for valid international mobile phone number [duplicate]

After stripping all characters except ‘+’ and digits from your input, this should do it: ^\+[1-9]{1}[0-9]{3,14}$ If you want to be more exact with the country codes see this question on List of phone number country codes However, I would try to be not too strict with my validation. Users get very frustrated if they … Read more

What is the best way for converting phone numbers into international format (E.164) using Java?

Google provides a library for working with phone numbers. The same one they use for Android http://code.google.com/p/libphonenumber/ String swissNumberStr = “044 668 18 00” PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); try { PhoneNumber swissNumberProto = phoneUtil.parse(swissNumberStr, “CH”); } catch (NumberParseException e) { System.err.println(“NumberParseException was thrown: ” + e.toString()); } // Produces “+41 44 668 18 00” System.out.println(phoneUtil.format(swissNumberProto, … 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 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

List of phone number country codes [closed]

I generated json file in the following format (Hope that it will help you) : { “countries”: [ { “code”: “+7 840”, “name”: “Abkhazia” }, { “code”: “+93”, “name”: “Afghanistan” }, { “code”: “+355”, “name”: “Albania” }, { “code”: “+213”, “name”: “Algeria” }, { “code”: “+1 684”, “name”: “American Samoa” }, { “code”: “+376”, “name”: … Read more

How to get current SIM card number in Android?

I think sim serial Number and sim number is unique. You can try this for get sim serial number and get sim number and Don’t forget to add permission in manifest file. TelephonyManager telemamanger = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String getSimSerialNumber = telemamanger.getSimSerialNumber(); String getSimNumber = telemamanger.getLine1Number(); And add below permission into your Androidmanifest.xml file. <uses-permission android:name=”android.permission.READ_PHONE_STATE”/> … Read more