deltachat / message-parser

Parsing of Links, Email adresses, simple text formatting (markdown subset), user mentions, hashtags and more in DeltaChat messages.
https://deltachat.github.io/message-parser/
Other
12 stars 2 forks source link

Implement parsing of telephone numbers #3

Open Simon-Laux opened 3 years ago

Simon-Laux commented 3 years ago

maybe first only support +[country] [area] [number]?

lk108 commented 1 year ago

That would be helpful for my use case.

Simon-Laux commented 10 months ago

android source code for this:

android/util/Patterns.java ```java /** * This pattern is intended for searching for things that look like they * might be phone numbers in arbitrary text, not for validating whether * something is in fact a phone number. It will miss many things that * are legitimate phone numbers. * *

The pattern matches the following: *

    *
  • Optionally, a + sign followed immediately by one or more digits. Spaces, dots, or dashes * may follow. *
  • Optionally, sets of digits in parentheses, separated by spaces, dots, or dashes. *
  • A string starting and ending with a digit, containing digits, spaces, dots, and/or dashes. *
*/ public static final Pattern PHONE = Pattern.compile( // sdd = space, dot, or dash "(\\+[0-9]+[\\- \\.]*)?" // +* + "(\\([0-9]+\\)[\\- \\.]*)?" // ()* + "([0-9][0-9\\- \\.]+[0-9])"); // + ```

Looks there are also standards for it, like https://en.wikipedia.org/wiki/E.164

the German wikipedia page for telephone numbers also contains some example formats that are used in Germany, Switzerland and Austria: https://de.wikipedia.org/w/index.php?title=Rufnummer&oldid=236385081#Nationales