Help on regex for phone number format XXX-XXX-XXXX

dianeramos
Tera Contributor

We have a requirement to have a standard format for the phone number field to be XXX-XXX-XXXX (with hyphens). Do you have any suggestions how i can achieve this by validation regex?

Thank you in advance

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Hi Diane,

We use this Regular Expression in a Variable Validation Regex for US Phone Numbers.

^\(?([0-9]{3})\)?[-]([0-9]{3})[-]([0-9]{4})$

View solution in original post

5 REPLIES 5

himanjaiswal
Tera Contributor
Try Below Code to convert Phone Number in xxx-xxx-xxxx
var pattern = /[^a-zA-Z0-9]/g;
        var cleanPhoneNum = phoneNum.replace(pattern, "");
        var formatPhn = cleanPhoneNum.substring(0,3)+"-"+cleanPhoneNum.substring(3,6)+"-"+cleanPhoneNum.substring(6,11);
 
Please mark correct if you find the above solution helpful. 🙂