flutter-form-builder-ecosystem / phone_number

Flutter plugin for parsing, formatting and validating international phone numbers.
https://pub.dev/packages/phone_number
BSD 3-Clause "New" or "Revised" License
81 stars 63 forks source link

RegEx (RegExp) for valid phone number #94

Closed Shawn-sudo closed 1 year ago

Shawn-sudo commented 1 year ago

Environment

Package version: 1.0.0

Description

What you'd like to happen:

Provide a RegExp of valid phone numbers.

RegExp is widely used to find a specific pattern in a text (string). To find for the phone number that a text contains, it'd be good to have the RegExp provided.

Example "Hey yo my phone number is +1 123 234 3456" --> "+1 123 234 3456" "Call me maybe 😉 123-2222-3333" --> "123-2222-3333"

RegEx for phone numbers that I found on the Internet: ^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3,4}[-\s\.]?[0-9]{4,6}$ I'm not sure if this would work well for every phone number formats of every country though.

My ultimate goal Ultimately, I just want a way to easily find the phone number that a text (string) contains. RegExp may not be the only solution for this, so if there's a better way to do this than using RegExp, please tell me

deandreamatias commented 1 year ago

Hi! Maybe a solution is add support in this plugin to the method findNumbers from libphonenumber. But, I don't know if exist a similar method on PhoneNumberKit.

Create and validate all RegEx for each country, is so hard that this plugin can't be offer this option in this moment

Shawn-sudo commented 1 year ago

I ended up using RegExp(r'[+]?(\d{1,3})?[\s.-]?\(?\d{1,3}\)?[\s.-]?\d{2,4}[\s.-]?\d{2,4}[\s.-]?(\d{2,4})?'), but this still doesn't support some countries that have special phone number format. I guess this isn't directly related to this plugin, so I'll close this.