Question: We have the demo [here](http://angular-ui.github.io/ui-utils/#/mask) on the angular-ui page.

Wondering how we can write a mask with optional extension number.

`(999) 999-9999 ext. 999` will make the extension required.

Answer: 
```
(999) 999-9999 ext. ?9?9?9

```

This will work good but if you want to clear on blur and put the mask back then you need a little more, I used like this

```
<input type='text'
  ng-model='customer.phone'
  ui-mask="{{phoneMask}}"
  ng-blur="removeMask()"
  ng-focus="placeMask()" />

```

And in my controller:

```
$scope.phoneMask= "(999) 999-9999 ext. ?9?9?9";
$scope.removeMask = function () {
   if ($scope.rep.phone.length === 10) {
        $scope.phoneMask= "(999) 999-9999";
    }
};
$scope.placeMask = function () {
  $scope.phoneMask= "(999) 999-9999 ext. ?9?9?9";
}

```

Hope it will help!
A good solution for this problem is to use [ngMask](https://github.com/candreoliveira/ngMask) which allows you to do exactly what you want without jQuery. To do that just add an '?' after the character you want to be optional:

`mask="9?9999-9999`

This is great for inputs like Brazilian phone numbers, which can have both 8 or 9 characters.