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

Prasad Dhumal
Mega Sage
Mega Sage

Try this

^([0-9]{3}-){2}[0-9]{4}$")

 

Sharing one more combination

/^(?:\(\d{3}\)|\d{3}-)\d{3}-\d{4}$/

 

 

 

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})$

Tejas Tamboli
Giga Guru

Hi @dianeramos 

One ServiceNow Community member has a useful thread from a couple of years ago.

Please go through this answer of Brad here:- 

How to validate a string field for proper phone number format

 

I hope this will help you.


Mark ✅ Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.

Thanks & Regards,
Tejas Tamboli