-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Contact Form: Improve phone no formatting #37603
Conversation
The modified regex fixes a few annoying issues with the phone input (such as duplication of country code)
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Sections (~124 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~92 bytes added 📈 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested, no obvious regressions, seems to work exactly as I'd hoped - thanks! 👍
const nationalNumber = stripNonDigits( inputNumber ).replace( | ||
new RegExp( '^(' + numberRegion.dialCode + ')?(' + numberRegion.nationalPrefix + ')?' ), | ||
let nationalNumber = stripNonDigits( inputNumber ).replace( | ||
new RegExp( '^(0{0,}' + numberRegion.dialCode + ')?(' + numberRegion.nationalPrefix + ')?' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotta admit, at first I thought it meant "0, followed by as many 0 as you can get".
AFAIK 0{0,}
== 0*
? If so, I'd say the latter is the clearer way of writing it IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I knew there was a better way, so obvious 😅
Thank you, great suggestion.
Changes proposed in this Pull Request
This PR introduces an improvement of formatting code of the phone input in the contact form, fixing a few annoying issues, and increasing its stability in general 🙏
Testing instructions
To replicate the issues (before applying the changes):
+441234567
), and then insert a0
between the+
and the first digit of the country code (i.e.+0441234567
). You'll notice the country code will be duplicated (in this example, it will become+44441234567
)000123456
), and then save. In theNetwork
tab of Dev Tools, check the phone number that is sent in the API call: it should be+44.00123456
(i.e. only one zero removed)After applying the fix:
+
and the first digit of the country code. Also verify that those zeroes will be removed once you submit (check the API call as well)000123456
with UK chosen as the country, becomes+44.123456
when sent to the backend)