Replace invalid data

0

I'm working on an input that can only accept

  • Numbers
  • Letter K (uppercase or lowercase)
  • middle script (-)

I have the following regular expression /^[Kk0-9-]+$/ to make only these types of data accepted. What I need is that every time the user types in this input any other data that is not valid is deleted.

I have the event ng-change function:

$scope.changeRutCliente = function(){
   if ($scope.rut_cliente.match(/^[Kk0-9-]+$/)) {
       console.log('is valid');
   } else {
       console.log('invalid');
   }
}

But I could not manage to have it delete the invalid data

    
asked by sioesi 21.04.2017 в 17:07
source

1 answer

1

I answer only xD, I found that when a ^ is prefixed to the regular expression, it denies them

then it would be like this:

$scope.rut_cliente = $scope.rut_cliente.replace(/[^Kk0-9-]+$/, "");
    
answered by 21.04.2017 / 17:30
source