user7112050 user7112050 - 1 year ago 84
AngularJS Question

How to replace coma and forward slash in input text field -- angularJs

ex: 1,23/456 should return 123456

this is and input field
so when i Type 1,23/456 in the input field and hit enter it should be changed to 123456

Answer Source

If the type of the input is number then it will automatically reject the slash. However I have faced compatibility issues with number fields when testing with IE

So you can register an ng-change or ng-blur event callback on your input field and you can define the callback function like this

$scope.onInputBlur = function(){
  //$scope.value is the model for your field
  $scope.value = $scope.value.replace(/,/,'','g'); // replace comma with empty string
  $scope.value = $scope.value.replace(/\//,'','g'); //replace slash with empty string

Hope this helps. :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download