Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular ng-pattern is ignored when using type=number

Tags:

angularjs

I am not seeing the ng-invalid class applied when I type into the field a string like abc. The ng-pattern works if i test it on the console...but not in angular.

<input type="number"
 step=".05"
 ng-pattern="/^\d{0,}\.{0,1}\d{0,}$/"
 ng-model="someNumber">
like image 239
chovy Avatar asked Jan 25 '26 03:01

chovy


1 Answers

@musically_ut's plnkr in the comments works for Firefox—i.e. the input element gets class ng-invalid for string abc—but not for Chrome.

For Chrome, it works for me if I add the required attribute, i.e.

<input type="number"
       step=".05"
       required
       ng-pattern="/^\d{0,}\.{0,1}\d{0,}$/"
       ng-model="someNumber">
like image 113
Daryn Avatar answered Jan 28 '26 16:01

Daryn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!