Angular highlights the text box with red if a non-integer number is used.
(function()
{
var app = angular.module('example', []);
app.controller('InputController', function()
{
this.number = '';
}
);
})();
<html ng-app="example">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<form ng-controller="InputController as ctl" ng-submit="inputForm.$valid">
<input type="number" step="0.001" pattern="(-|\+)?\d*\.?\d+" ng-model="ctl.number">
<input type="submit">
</form>
</html>
If I set the step
to, for example, 0.001
, then it will highlight red when I put anything with more than three decimal places, e.g. 9.1234
.
If I put the pattern (-|\+)?\d*\.?\d+
, that changes nothing.
Combining step with pattern does not fix my problem.
How can I get it to accept anything that's a number, not just integers, and only numbers?