05/31/2023 07:53 AM
Hello,
We're trying to update the phone number regex to allow for an extension to be added, so a phone number value could be something like +1 123 456 7890 x1212. However, when we updated these values var phoneRegex1 and var phoneRegex2 in the users/create.gsp file we found it wasn't working as expected.
For reference, this is the regex we're using which we've validated with a regex syntax validator. But let me know if I'm missing something else.
regex 1 - /^[+]*[(]{0,1}[0-9]{1,3}[)]{0,1}[-\s\./0-9]*[x0-9]*[^-/(+@#$%\^&*!]$/;
regex 2 - /^[+]*[(]{0,1}[0-9]{1,3}[)]{0,1}[-\s\./0-9]*[x0-9]*[^-/(+@#$%\^&*!]$/g
Thanks
06/01/2023 10:39 PM
Hello @GOE,
Could you please attempt to use the following sample regex?
Regex Sample:
^\+?[1-9]\d{1,14}$
The above regex will match the following examples:
+14155552671 (US)
+442071838750 (GB)
+551155256325 (BR)
ThankYou!
06/06/2023 06:06 AM
Hello,
Would this allow for the letter x if the user has an extension? That's essentially what I'm trying to achieve.
06/06/2023 07:51 AM
Hello @GOE ,
The Above regular expression is designed to match a phone number with an optional "+" sign at the beginning, followed by one digit from 1 to 9, and then between 1 and 14 digits. It does not consider any letters or extensions.
You can modify the regular expression to allow for an extension designated by the letter `x` by adding an optional group at the end of the expression. You may try the below sample and check.
^\+?[1-9]\d{1,14}(x\d+)?$
Thanks