Update Regex for Phone Number #2294
Conversation
|
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,}$"; | |||
skendrot
Jul 12, 2018
Contributor
No need to keep the old RegEx. Version history will have it
No need to keep the old RegEx. Version history will have it
| @@ -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}"; | |||
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
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
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
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
avknaidu
Jul 13, 2018
Author
Member
i see what you mean. Let me take a look.
i see what you mean. Let me take a look.
|
@avknaidu, 4.0 code freeze is next week, do you think you can make it with this PR? |
|
ping @avknaidu |
|
ping @skendrot |
|
With new changes the following is considered to be a valid phone number |
|
@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 Let me know your thoughts. |
|
Sounds good. Looks like there are conflicts so resolve those and we should be good |


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:
Other information