Ionic get user's phone number

I'm very new to ionic and cordova. I want to get user's phone number somehow, is it possible? I'm trying to create number registration for my app. When user opens an app the very first time he is asked to enter a code that he gets via text message. It's similar to viber. The first view contains a button 'Send me a code', and the next view has a form 'Enter code:' and a button 'Log me in'.

I think this plugin will full fill your needs (https://github.com/vliesaputra/DeviceInformationPlugin). It will give the following data

1.Your unique Device ID

2.Phone Number (if it is stored in your SIM card)

3.Country ISO of your phone network provider

4.Name of your network provider

5.Your SIM Card Serial number

6.Country ISO of your SIM card 7.Name of your SIM card mobile operator

8.E-mail/Phone number used by apps listed in your Settings > Accounts & Sync list

Here is sample code

var deviceInfo = cordova.require("cordova/plugin/DeviceInformation");
deviceInfo.get(function(result) {
      //fetch the device data
        console.log("result = " + result);
    }, function() {
        console.log("error");
    }); 

Even though this is possible, it isn't really that related to Cordova or Ionic. What you want to do is to have back-end server which handles all other parts than collecting the phone number and the code after it. These both are actually handled by your back-end server. The flow would look something like this:

  1. Ask for phone number on Cordova app.
  2. After user hits submit, Cordova app sends the phone number to back-end server via HTTP (AJAX).
  3. Back-end server then generates the phone number - verification code pair and sends the verification code for user via SMS gateway.
  4. User receives the verification code message and submits it again through the Cordova app.
  5. Cordova app sends the verification code to the back-end server which checks it and if ok, tells that as a return value for Cordova.