Below is the code I've created for an angularjs directive that removes spaces. It successfully eliminates spaces between words, but unfortunately still allows leading spaces.
function customValidation() {
return {
require: 'ngModel',
link: function(scope, element, attrs, modelCtrl) {
modelCtrl.$parsers.push(function (inputValue) {
var transformedInput = inputValue.toLowerCase().replace(/ /g,'');
if (transformedInput!== inputValue) {
modelCtrl.$setViewValue(transformedInput);
modelCtrl.$render();
}
return transformedInput;
});
}
};
}