HTML allows nothing but a number or a decimal number (using step="any" to be careful, this will make angular consider it invalid ... however, you can create your own validation method in the controller:
$scope.validated = function(){ if (null !== $scope.pnr) ){ $scope.pnr = $scope.pnr.split("-").join(); if(typeof parseInt($scope.pnr, 10) = 'integer') return true; else return false; } else { return false; } };
it's just a random check of not necessarily what you want ...
Then it has the ng-class "error", which is included if checked === false
something like:
<form name="myForm" ng-submit="validated && submittedSSN"> ng-class="{strike: deleted, bold: important, 'has-error': error}" <input type="number" ng-class=" {error: !validated}" ng-model="pnr" pnrvalidator /> </form>
CSS should also have something for error.
.error { background: red; border:red; color: lime; }
- Pay attention to this joke, which will be insane.
https://docs.angularjs.org/api/ng/directive/ngClass
Also see iPhone UIWebview: how to get a numeric keypad? Is it possible? How to add custom validation to an AngularJS form?
Accordingly, you can make type="tel" , which will only work with Safari.
Zargold
source share