- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2022 10:33 PM
Dear All,
Greetings !!!
I have a requirement to create a Phone Number variable on a catalog item which is supposed to follow E164 format. Since E164 type is not available on a catalog item, I have created a Single Line Text type field, however, I am facing issues while creating Regex for this field. My requirement is to allow users to enter numbers, spaces and special characters such as brackets, hyphen, plus sign. On top of that, they should not be able to enter alphabets in this field. A few valid examples of valid phone numbers are:
1. +1 (201) 515-1633
2. +919876543210
3. 9876512345
4. 201-515-1633
5. 987 654 321
I would like to keep spaces and special characters(brackets, plus sign, hyphen, spaces) to be optional. I have tried creating Regex for this requirement but apparently I haven't able to create the correct one. Could someone help me to create Regex for this requirement please?
Thanks & Regards,
Gulzar Manuja
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2022 10:59 PM
Can try this should work
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
/*^\s* #Line start, match any whitespaces at the beginning if any.
(?:\+?(\d{1,3}))? #GROUP 1: The country code. Optional.
[-. (]* #Allow certain non numeric characters that may appear between the Country Code and the Area Code.
(\d{3}) #GROUP 2: The Area Code. Required.
[-. )]* #Allow certain non numeric characters that may appear between the Area Code and the Exchange number.
(\d{3}) #GROUP 3: The Exchange number. Required.
[-. ]* #Allow certain non numeric characters that may appear between the Exchange number and the Subscriber number.
(\d{4}) #Group 4: The Subscriber Number. Required.
(?: *x(\d+))? #Group 5: The Extension number. Optional.
\s*$ #Match any ending whitespaces if any and the end of string.*/
var number= g_form.getValue('phonenumber');
var pattern = /^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$/;
if(!pattern.test(number)){
alert('Phone enter a valid phone number');
}
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2025 08:32 AM
The advantage of doing this as a "Question Regular Expression" is that is reusable throughout the catalog without having to introduce a client script on every catalog item. My catalog has multiple items where there is some sort of phone variable, and there are more to come. If I have a regex value for phone, I just have to select a drop-down value for the phone variable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2022 11:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2022 01:19 AM
Hi Vaishnavi,
Thanks a lot for your response. It really helped. Appreciate it.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2022 11:53 PM
Hey,
I think there is a no code way to achieve this:
Follow below article for the same:
Field validation: Regular Expressions
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2022 12:28 AM
Hello ,
For validation you have to create on change client script on mobile number field
Attaching screen shot for the same
******************code snippet********************
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading || newValue == ''){
return;
}
// Allows formats of (999) 999-9999, 999-999-9999, and 9999999999
var pattern = /^[(]?(\d{3})[)]?[-|\s]?(\d{3})[-|\s]?(\d{4})$/;
if(!pattern.test(newValue)){
alert('Phone enter a valid phone number');
g_form.setValue('u_mobile_number', '');
}
}
**************************************************
Thank you,
PLEASE mark my ANSWER as CORRECT if it served your purpose.