Límite de caracteres en el texto de entrada

Quiero que mi cuadro de texto solo permita números y también tenga un límite de caracteres.

Actualmente, tengo los números funcionando ... Ahora tengo problemas para descubrir cómo limitar los caracteres.

Esto es lo que tengo ...

JS:

app.directive('numbersonly', function () {
    return {
        restrict: 'A',
        link: function (scope, elm, attrs, ctrl) {
            elm.on('keydown', function (event) {
                if (event.which == 64 || event.which == 16 && elm.val().length > 4) {
                    return false;
                } else if (event.which >= 48 && event.which <= 57) {
                    return true;
                } else if (event.which >= 96 && event.which <= 105) {
                    return true;
                } else if ([8, 13, 27, 37, 38, 39, 40].indexOf(event.which) > -1 && elm.val().length > 4) {
                    return true;
                } else {
                    event.preventDefault();
                    return false;
                }
            });
        }
    }
});

Margen:

<input type="text" id="txtEmpAge" data-ng-model="newemployee.Age" class="form-control" numbersonly required />

Respuestas a la pregunta(2)

Su respuesta a la pregunta