Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Regex for Phone Number #2294

Merged
merged 10 commits into from Oct 12, 2018
Merged

Update Regex for Phone Number #2294

merged 10 commits into from Oct 12, 2018

Conversation

@avknaidu
Copy link
Member

@avknaidu avknaidu commented Jul 12, 2018

Issue: #1821

PR Type

What kind of change does this PR introduce?

Refactoring

What is the current behavior?

What is the new behavior?

Improves Phone Number Regex Validation.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Docs have been added/updated which fit documentation template. (for bug fixes / features)
  • Sample in sample app has been added / updated (for bug fixes / features)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

Other information

@kbrons
kbrons approved these changes Jul 12, 2018
Copy link
Contributor

@kbrons kbrons left a comment

Looks good, but I think it'd be nice to add to the docs that, if the regex doesn't cover a specific phone format the developer wants to validate, they can set the regex property themselves with a different regex.

@@ -13,7 +13,8 @@ namespace Microsoft.Toolkit.Extensions
/// </summary>
public static class StringExtensions
{
internal const string PhoneNumberRegex = @"^\s*\+?\s*([0-9][\s-]*){9,}$";
// internal const string PhoneNumberRegex = @"^\s*\+?\s*([0-9][\s-]*){9,}$";

This comment has been minimized.

@skendrot

skendrot Jul 12, 2018
Contributor

No need to keep the old RegEx. Version history will have it

avknaidu added 2 commits Jul 13, 2018
@@ -13,7 +13,7 @@ namespace Microsoft.Toolkit.Extensions
/// </summary>
public static class StringExtensions
{
internal const string PhoneNumberRegex = @"^\s*\+?\s*([0-9][\s-]*){9,}$";
internal const string PhoneNumberRegex = @"(\([0-9]{3}\) ?)[0-9]{3}-[0-9]{4}|[0-9]{3}-?[0-9]{3}-?[0-9]{4}|([00|+][0-9]{1,2}) ?[0-9]{3}-?[0-9]{3}-?[0-9]{4}";

This comment has been minimized.

@skendrot

skendrot Jul 13, 2018
Contributor

Doesn't work for standard US phone numbers with the country code
19876543210

Readable format: 1-987-654-3210
I think this should be covered if we're changing the format

This comment has been minimized.

@avknaidu

avknaidu Jul 13, 2018
Author Member

image

image

Works in both cases.

This comment has been minimized.

@skendrot

skendrot Jul 13, 2018
Contributor

It returns a valid phone number true, but if you get the match it would be the first 10 digits (leaving the zero at the end off).
It also reports that 17744548445454545454545455454545454454545 is a valid phone number with four matches

This comment has been minimized.

@avknaidu

avknaidu Jul 13, 2018
Author Member

i see what you mean. Let me take a look.

@nmetulev
Copy link
Contributor

@nmetulev nmetulev commented Jul 23, 2018

@avknaidu, 4.0 code freeze is next week, do you think you can make it with this PR?

@nmetulev
Copy link
Contributor

@nmetulev nmetulev commented Sep 24, 2018

ping @avknaidu

nmetulev and others added 3 commits Sep 24, 2018
@avknaidu
Copy link
Member Author

@avknaidu avknaidu commented Sep 26, 2018

@nmetulev changes completed. Things took a u turn for me in the past few months. was not able to complete this on time.

@skendrot please check now. I changed regex now. Updated docs showing formats that are supported.

@avknaidu
Copy link
Member Author

@avknaidu avknaidu commented Oct 2, 2018

ping @skendrot

@nmetulev nmetulev mentioned this pull request Oct 3, 2018
4 of 4 tasks complete
@skendrot
Copy link
Contributor

@skendrot skendrot commented Oct 8, 2018

With new changes the following is considered to be a valid phone number 123456-555-1234. Should this be valid? Not sure if it's saying it's a valid country code, followed by a number. If this is valid then I would say we're good to go. If it's not valid, is this an acceptable false positive?

@avknaidu
Copy link
Member Author

@avknaidu avknaidu commented Oct 12, 2018

@skendrot i personally cannot make a judgement if that format is a valid format or not. I came across a bunch of new formats that i never know a phone number can be written in. So i cannot make a judgement on that particular format.

However from the general format of [CountryCode(Max 3 Digits)][Phone Number], i think it is a valid number. Also note, the IsPhoneNumber is something which is only based on regex providing sample phone number formats with just a lightweight Extension where in there is a whole Library doing this, I think this should be a pretty acceptable solution.

Let me know your thoughts.

@skendrot
Copy link
Contributor

@skendrot skendrot commented Oct 12, 2018

Sounds good. Looks like there are conflicts so resolve those and we should be good

@nmetulev nmetulev merged commit cf6240d into windows-toolkit:master Oct 12, 2018
3 checks passed
3 checks passed
Toolkit-CI Build #20181012.7 succeeded
Details
WIP ready for review
Details
license/cla All CLA requirements met.
Details
@avknaidu avknaidu deleted the avknaidu:RegexUpdate branch Oct 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.