Here is my source code. I have written a directive in angularjs to eliminate spaces. It's perfectly working for spaces between words but is still allowing spaces at the beginning.
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;
});
}
};
}