Hi Guys,
I am trying to validate the number input that I have the user must enter a
digit with a value greater than 0, this works initially but the moment the
user enters the dot for decimal part of the amount the error message that I
have on ng-show is shown eg "36.95" the moment the dot is entered the error
message pops up but entering any digits after the dot makes the error
message disappear again.
The input validation also breaks when the user enter more than two dots in
the figure this should not be allowed, how can I check and validate this?
below is my code
<p>
<label for="expenseAmount">Expense amount</label>
<input type="number" step="any" name="expenseAmount" ng-min="1"
ng-maxlength="8" ng-model="newExpense.amount" required placeholder="Expense
amount" >
<i ng-show="addExpenseForm.expenseAmount.$valid" class="fa fa-check fa-lg
green"></i>
<i ng-show="addExpenseForm.expenseAmount.$error.maxlength ||
addExpenseForm.expenseAmount.$touched &&
addExpenseForm.expenseAmount.$invalid " class="fa fa-times fa-lg red"></i>
</p>
<span class="red" ng-show="addExpenseForm.expenseAmount.$touched &&
addExpenseForm.expenseAmount.$invalid &&
!addExpenseForm.expenseAmount.$error.maxlength"> Please enter a valid
amount greater than 0.</span>
<span class="red" ng-show="addExpenseForm.expenseAmount.$error.maxlength">Up
to 8 digits allowed.</span>
I have also tried to put the string into an array like below but I keep
getting the undefined function error (this is an incomplete function I'm
still working on it)
$scope.saveExpense = function(expenseItem){
if(angular.isDefined(expenseItem) && angular.isDefined(expenseItem.detail)
&& angular.isDefined(expenseItem.amount))
{
$scope.list.push({ date: $scope.myDate, detail: expenseItem.detail, amount:
expenseItem.amount });
alert("Item added");
checkString = expenseItem.amount.split();
count = 0;
for (var i = 0; i < expenseItem.amount.length; i++) {
if (checkString[i] == ".") count += 1;
console.log("checkString[i] = " + i + "count = " + i);
};
expenseItem.detail = "";
expenseItem.amount = "";
}
}
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.