We are delighted to share our new EIC Delivery Methodology for efficiently managing Saviynt Implementations and delivering quick time to value. CLICK HERE.

Phone Regex Validator

GOE
Regular Contributor
Regular Contributor

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. 

  1. Is that the right regex file we should be making updates to.
  2. If yes, are those the right parameters we should be changing or are we missing something?

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

3 REPLIES 3

sudeshjaiswal
Saviynt Employee
Saviynt Employee

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!

If you find the above response useful, Kindly Mark it as "Accept As Solution".

GOE
Regular Contributor
Regular Contributor

Hello,

Would this allow for the letter x if the user has an extension? That's essentially what I'm trying to achieve.

sudeshjaiswal
Saviynt Employee
Saviynt Employee

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

If you find the above response useful, Kindly Mark it as "Accept As Solution".