Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Regex for phone numbers.

Andrew122
Mega Expert

I'm not too good with Regex.  Does anyone know how I could format it so that a phone number field will accept only numbers, parentheses, and minus signs?  Currently it's set up as /^\d+$/ and the field only accepts numbers.

1 ACCEPTED SOLUTION

Dinesh Nikam
Mega Guru

Hello ,

For validation you have to create on change client script on mobile number field

Attaching screen shot for the same

find_real_file.png 

******************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.

View solution in original post

5 REPLIES 5

Dinesh Nikam
Mega Guru

Hello ,

For validation you have to create on change client script on mobile number field

Attaching screen shot for the same

find_real_file.png 

******************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.