Hey Everyone I'm working in angular and I am trying to create a filter that just allows numbers in the format of "any amount of digits . any amount of digits"
Otherwise is will prevent the entry if it's not in the format of [0-9.]
. The pattern is still allowing numbers like this 000.00.
in the input field.
How do I stop it from inserting that last decimal point? Thank you for your assistance ahead of time!
code
$scope.filterValue = function($event, value){
var char = String.fromCharCode($event.keyCode);
if(value === null){
if(isNaN(char)){
$event.preventDefault();
}
}else{
var pattern = /^-?[0-9]{0,}\.?[0-9]{0,}$/;
if(pattern.test(value)){
if(isNaN(char) && (value.indexOf(".") == value.length-1)){
$event.preventDefault();
}
}else{
$event.preventDefault();
}
}
};