12

I have the issue with <md-autocomplete> component which is shown in this demo:

<md-autocomplete ng-pattern="..."> does not work. I would expect that if some text is entered into Tax field (like zzz) the field is be marked as red as only numbers [1..99] are accepted by regex ng-pattern="/^[1-9]\d?$/". Actually required works fine: when the field is empty, it is triggered as invalid.

dma_k
  • 10,431
  • 16
  • 76
  • 128

3 Answers3

11

That seems to have been a bug with Angular Material. It was apparently fixed in 1.1.4:
ng-pattern for md-autocomplete #9755

Here's a working demo. All I did was update the two angular-material libraries.

https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.1.4/angular-material.min.js
https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.1.4/angular-material.min.css
wwv
  • 891
  • 5
  • 14
3

The issue with ng-pattern got fixed in version 1.1.14. I have updated the Demo and added latest angularjs-material.js

I have not changed ng-pattern, it remains same.

ng-pattern="/^[1-9]/"

Now the field will change to red if other than number is entered.

Srikanth B
  • 143
  • 2
  • 7
2

Just change your pattern by: ng-pattern="^[1-9]\d?$"

haMzox
  • 2,073
  • 1
  • 12
  • 25
  • I have tried to change it to the pattern you've said (see [updated demo](https://jsfiddle.net/j9afow1L/5/)), however it has no effect. More over `` does not work as expected as well (previously was marked as red). Could you please update the demo so that it works? Thanks! – dma_k May 11 '17 at 07:29