app.directive('lettersOnly', function () {
  return {
    require: 'ngModel',
    link: function (scope, element, attr, ngModelCtrl) {
      function onlyLetters(text) {
        if (text) {
          var transformedInput = text.replace(/[^A-Za-z]/g, '');

          if (transformedInput !== text) {
            ngModelCtrl.$setViewValue(transformedInput);
            ngModelCtrl.$render();
          }
          return transformedInput;
        }
        return undefined;
      }
      if (attr.lettersOnly === 'true') {
        ngModelCtrl.$parsers.push(onlyLetters);
      }
    }
  };
});