в черновом варианте как-то так
<div ng-app="HelloHabr">
<form name="userForm">
<input class="form-control" type="text" name="LovelyMimimi" ng-model="mimimi" mimimi/>
<button type="submit" class="btn btn-primary" ng-disabled="userForm.$invalid">Submit</button>
</form>
<style>
input.ng-valid {
background-color: #81F7F3;
}
input.ng-invalid {
background-color: #F78181;
}
</style>
js
var app = angular.module('HelloHabr', []);
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
app.directive('mimimi', function () {
return {
require: 'ngModel',
link: function (scope, elm, attrs, ctrl) {
ctrl.$setValidity('mimimi', false);
ctrl.$parsers.unshift(function (mimimi) {
mimimi = (mimimi.replace(',', "."));
if (isNumeric(mimimi))
{
ctrl.$setValidity('mimimi', true);
return mimimi.toUpperCase();
}
else
{
ctrl.$setValidity('mimimi', false);
return undefined;
}
});
}
};
});