0

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">
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122

2 Answers2

0

Use <input type="number" /> or sanitize the model value using a regular expression.

console.log('1,23/456'.replace(/[^0-9]/g, ''));
Dan Wilson
  • 3,937
  • 2
  • 17
  • 27
0

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

Manish Gharat
  • 400
  • 1
  • 10