Question: I am trying to validate my mobile number which I am picking up from **Contac List** but **the problem is that** it is picking contact like **+91 95 xx xxxxxx** and there is space between numbers so the validation is not happening.
For now I am using this validation

```
String Mobile = "^[+]?[01]?[- .]?(\\([2-]\\d{2}\\)|[2-9]\\d{2})[- .]?\\d{3}[- .]?\\d{4}$";

```

But it's a failure.
Any help is appreciable.
Thank you.

Answer: 
Replace the spaces then validate..

```
String phone=phone.replace(" ","");

```

Now the String phone has the text without spaces and you can compare.
you can use below code :

```
phoneNumber = phoneCursor.getString(phoneCursor.getColumnIndex(NUMBER));
try 
{
    if (phoneNumber != null)
        phoneNumber = extractDigits(phoneNumber);
} 
catch (Exception e) 
{   
    e.printStackTrace();
}

```

where **extractDigits()** method is as :

```
public static String extractDigits(String src) 
{
    StringBuilder builder = new StringBuilder();
    String firstchar = src.substring(0, 1);
    for (int i = 0; i < src.length(); i++) 
    {
        char c = src.charAt(i);
        if (Character.isDigit(c) || firstchar.equals("+")) 
        {
            firstchar = "";
            builder.append(c);
        }
    }
    return Checkvalidnumber(builder.toString());
}

```

where **Checkvalidnumber()** method is as :

```
public static String Checkvalidnumber(String number) 
{
    String validnumber = "";
    String Countrycode = chatPrefs.getString("countryCode", "");
    if (number.startsWith("+")) 
    {
        validnumber = number.trim();
    } 
    else if (number.startsWith("0")) 
    {
        validnumber = (Countrycode + number.substring(1, number.length())).trim();
    } 
    else 
    {
        validnumber = (Countrycode + number).trim();
    }

    return validnumber;
}

```