Regex for int phone no (simplified) + regex tester

Contains tips for configurators working with Aware IM
Post Reply
hpl123
Posts: 2594
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Regex for int phone no (simplified) + regex tester

Post by hpl123 »

Hi all,
Here is a simplified regex for international phonenumbers and can probably be done in some other way but this works for my purposes.

The regex is:

Code: Select all

 ^\+\d+$
I use it to validate phone numbers and the regex basically makes sure the number starts with a + sign and is followed by numbers only (no spaces, alpha or special characters) so numbers like these work:
+4612345678
+4512345678

I use it in different places but to give you an example of a rule where I use it:

Code: Select all

If MATCHES(Reservation.Phone, '^\+\d+$')='No'
Then
I used the following regex tester to create/test the regex and works great:
https://regex101.com/
Henrik (V8 Developer Ed. - Windows)
hpl123
Posts: 2594
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Re: Regex for int phone no (simplified) + regex tester

Post by hpl123 »

Update:
This revised version also looks at number of characters and has to be 5-20 characters to be valid:

Code: Select all

^\+\d{5,20}$
Henrik (V8 Developer Ed. - Windows)
Post Reply