Can you have multiple validation regrex formats?

DevtoSME
Giga Guru

I want to include international numbers for the phone number field and allow if the number +1 is included. so the regrex I have now is ^\+?[1-9]\d{0,2}[-. ]?\(?\d{1,4}?\)?[-. ]?\d{1,4}[-. ]?\d{1,9}$

 

 

However some testers are using manually created user accounts to test and the profiles have numbers with spaces like (303) 748-9843. Am I able to include another format to include spaces or can i use one regrex that can account for spaces and non space telephone numbers? I'm not familiar with this feature and I've looked up a few and  it doesn't specify having more than one or include both spaces and non spaces.

 

5 REPLIES 5

Marcos Kassak
Kilo Sage
Kilo Sage

Hi @DevtoSME,

 

I have rebuilt your regex to validate a few more examples, here's the regex:

 

^\+?[1-9]\d{0,2}[-. ]?\(?\d{1,4}\)?[-. ]?\d{1,4}[-. ]?\d{1,9}$

 

The pattern will allow numbers like this:

 

+1 (303) 748-9843

+44 20 7946 0958

(303) 748-9843

303 748 9843

303-748-9843

303.748.9843

 

You can use this website https://regexr.com/ to validate your regex expression against the text above (do not paste them all, it will test only one per time)

 

Let me know how it goes.

 

If you found my answer helpful or correct ✔️ in any way, please don't forget to mark it to help future readers! 👍

 

--

 

Kind regards,


Marcos Kassak
Solution Consultant  🎯

Hey thank you so much for responding it look like there's two formats that aren't working when I used the regrex you put down. I'll attach screen shots but its the one i need the most which is 

(303) 748-9843

Hi @DevtoSME,

 

I have created one specific for (303) 748-9843 to keep it simple, please test:

 

^\(\d{3}\) \d{3}-\d{4}$

 

The output from the site confirming that worked:

 

MarcosKassak_0-1729711078477.png

 

If you need more scenarios we can adapt again.

 

DevtoSME
Giga Guru

Hi Marcos thank you fro your reply however the original ask was for international numbers to be included .

so all formats included space and no spaces PLUS +1 is what I'm looking for, is there a regrex for that?

 

+1 (303) 748-9843

+44 20 7946 0958

(303) 748-9843

(303) 748 9843

303 748 9843

303-748-9843

303.748.9843