0

I have tried matching Phone numbers with the regular expressions provided by Android in Patterns.Phone,this matches a lot of things that are not phone numbers.I have also tried using:

(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?

However,I found that the Test was not successfull for all the inputs.I would like to validate the following inputs using a regular expression:

  67450450
  +9144-27444444
  27444444 
  27470570
  +12142261347
  +61406366180
  0891 2577456
  2577456
  +91 9550461668
  9550461668
  03-1234567  
  1860 425 3330 

Basically any nymber format supported here:WTND

vamsiampolu
  • 6,328
  • 19
  • 82
  • 183
  • possible duplicate of [A comprehensive regex for phone number validation](http://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation) – mmmmmm Feb 03 '15 at 23:01

2 Answers2

1
you can use the following code to check phone #:

    private boolean validPhone(String phone) {
        Pattern pattern = Patterns.PHONE;
        return pattern.matcher(phone).matches();
    }



if(validPhone("67450450")){
  Toast.makeText(this,"The phone number is valid");
}
 else
{
  Toast.makeText(this,"The phone number is not valid");
}
Mohammed Saleem
  • 568
  • 5
  • 20
0

This isn't clean/efficient, just thrown together to match your sample data:

\b\d{7,10}|\+\d{4}-\d{8}|\+\d{11}|\d{4}\s\d{7}|\+\d{2}\s\d{10}|\d{2}-\d{7}|\d{4}\s\d{3}\s\d{4}\b
gwillie
  • 1,893
  • 1
  • 12
  • 14