user7112050 user7112050 - 11 months ago 56
Javascript Question

How to replace comma and forward slash in input text field

Example: "1,23/456" should return "123456"

So when I type "1,23/456" in the input field and hit "enter" it should be changed to "123456".

<input id="Id" ng-model="Id" name="searchInput" type="text">

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. :)