The ui-mask in `Angular UI Utils' project (link) is a bit too limited. 
For example, the first digit of a US phone number should be 2-9. In ngPattern, it should be 
ng-pattern="/^\([2-9]\d{2}\)\d{3}-\d{4}(x\d{1,4})?$/"
So how can I write an input mask to prevent users from entering 0 or 1 in the first digit? Is there some better input mask we should use for Angular?
I guess you can find your answer here: https://github.com/angular-ui/ui-utils/issues/16
As it is explained in the link you can get the mask from a scope/controller variable, check the input and change the mask as needed like:
<input type="text" ui-mask="{{mask}}" ng-keyup="onKeyUp()" ng-model="myinput">
$scope.myinput = '';
var defaultMask  = '(99) 9999-9999';
$scope.mask = defaultMask;
$scope.onKeyUp = function(){
  if ($scope.myinput.slice(0,3) == '119') { // (11) 9 means mobile, or instead, you could use a regex
    $scope.mask = '(99) 99999-9999';
  } else {
    $scope.mask = defaultMask;
  }
};
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With