Siddharth Siddharth - 3 months ago 8x
Android Question

How to get last 4 digit of number in android?

I have an app which contain mobile number edit text in which user can edit mobile number and I have to send two request to server like:- mobile number and mssdn,mobile number(which is full lenghth ) and mssdn(which contain mobile number last 4 digit).How can I do that

sJy sJy

Try this. Check for length greater than 4 before calling subString to avoid IndexOutOfBounds Exception.

    EditText mEdtPhoneNumber = (EditText) findViewById(;
    String phoneNumber = mEdtPhoneNumber.getText().toString().trim();
    String strLastFourDi = phoneNumber.length() >= 4 ? phoneNumber.substring(phoneNumber.length() - 4): "";

Also what is mssdn?? Is it msisdn??