Follow these regular expressions.
^[0-9]{4,6}\-[0-9]{6}(?:\s(?:ext|x)\s[0-9]{3,4})?$
And here to capture the number groups:
^([0-9]{4,6})\-([0-9]{6})(?:\s(?:ext|x)\s([0-9]{3,4}))?$
And here is the expression cleaned up:
^(\d{4,6})\-(\d{6})(?:\s(?:ext|x)\s(\d{3,4}))?$
Hope this will help you.