javascript - angularjs directive to only allow alphabetic characters and numbers -


i've been trying implement directive restrict using of symbols such as

@,#,$,%,^,:),:d etc. tried following directive. works first time enter can enter these symbols. there more efficient directive can use.

this directive used.

app.directive('onlyalphabets', function() {   return {     require: 'ngmodel',     link: function (scope, element, attr, ngmodelctrl) {       function fromuser(text) {         var transformedinput = text.replace(/[^0-9a-z]/g, '');         console.log(transformedinput);         if(transformedinput !== text) {             ngmodelctrl.$setviewvalue(transformedinput);             ngmodelctrl.$render();         }         return transformedinput;       }       ngmodelctrl.$parsers.push(fromuser);     }   };  }); 

i think regex should be: /[^0-9a-z]+/g


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -