I have an input where I enter data and the first 3 numbers are separated with a - and the next 3 as well and the rest are not:
001-001-123234344
What I need is that this entry only allows having the - and not another symbol like {}()+*# ... ect
this is my code
<input type="text" ng-model="data.dato" ng-change="cambios()" maxlength="17"><br>
and in my controller I have the following
$scope.data = {};
$scope.cambios = function(){
if($scope.data.dato.length === 3 || $scope.data.dato.length === 7){
$scope.data.dato = $scope.data.dato+'-';
}
if($scope.data.dato.length === 17){
$scope.final = $scope.data.dato.replace(/-/g,'');
alert($scope.final)
}
}
Finally, in the first if the - is added, when I have already entered all the data and I would like to delete everything and it remains empty, it is not deleted, how can I control that?
I thank you in advance
You can use Angular ui-mask
Here is the link so you know how to use it and download it https://github.com/angular-ui/ui-mask
And here you can see it working online: https://htmlpreview.github.io/?https://github.com/angular-ui/ui-mask/master/demo/index.html
but practically it is to define the mask in your input in this way
I hope this helps.