| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 1× 2× 1× 2× 2× 4× 1× 3× 1× | function ValidateNumberDirective () {
return {
require: 'ngModel',
restrict: 'A',
link
};
function link (scope, element, attrs, ctrl) {
const pattern = /^\d+(\.\d{1,2})?$/;
ctrl.$validators.number = function numberValidator (modelValue, viewModel) {
if (pattern.test(viewModel)) {
return true;
}
return false;
};
}
}
ValidateNumberDirective.$inject = [];
export default ValidateNumberDirective;
|