Search code examples
regexdevexpressphone-numbermaskedtextbox

Devex TextEdit Input Mask Regex for US Phone Numbers


I'm using a Devex TextEdit control in a WInForms application. I want to use a regular expression mask on the control for formatting US phone numbers. I'm currently using this:

((\d{3}))-(\d{3})-(\d{4}) x(\d*)

(888) 555-1212 x235

I want to make the extension optional. The above Regex always places the x at the end if there's no extension ( (888) 555-1212 x ).

I have basic regex knowledge, but I don't know how to use it in a mask.

Thanks in advance.


Solution

  • Found it:

    ((\d{3}))-(\d{3})-(\d{4}) (x(\d*))?