Reputation: 43
I'm currently developing an Optical Character Recognition(OCR) apps which will pass the recognized data from the business card into the contact.I already managed to recognized the data from the business card.
The question is how to recognized the things such as phone number in that text box and pass it into the phone contact textfield ?
Upvotes: 1
Views: 66
Reputation: 6089
You can try this:
String text = "This is the text 2432423 which contains phone numbers 56565555";
Pattern pattern = Pattern.compile("\\d{5,12}"); // at least 5 at most 12
// before match remove all the spaces, to ensure the length on numbers is OK it will work more better.
Matcher matcher = pattern.matcher(text.replaceAll(" ", ""));
while (matcher.find()) {
String num = matcher.group();
System.out.println("phone = " + num);
}
And this the output:
phone = 2432423
phone = 56565555
Note: The at least and at most, you can change as your requirement.
Upvotes: 1