validation - How to validate age using Angularjs? -


we using angular js our project. , validation handling through angular js.

we able validate text field except drop down box.

we have 3 dropdown box datefields(dd mm yyyy). have 2 questions...

  1. how can fetch values these 3 dropdown , how form date.

  2. then, want validate date (if age greater 50 set error flag). how can using angular js? want set form invalid if user select age beyond 50.

please suggest me this? i'm new angular js.

i don't have code base answer off of, here function identify correct age:

$scope.datediff = function(birthmonth, birthday, birthyear) {     var todaydate = new date(),         todayyear = todaydate.getfullyear(),         todaymonth = todaydate.getmonth(),         todayday = todaydate.getdate(),         age = todayyear - birthyear;       if (todaymonth < birthmonth - 1)     {       age--;     }      if (birthmonth - 1 === todaymonth && todayday < birthday)     {       age--;     }     return age; };  $scope.datediff(8,15,1963); // return 50 birthday has passed $scope.datediff(9,15,1963); // return 49 birthday has not yet happened 

in html use ng-options allow user select dates dropdown list.

day <select ng-model="selectedday" ng-options="day day.date day in days"></select> 

here full working example.

being you're new angular, make sure take time learn how code works. ng-options may seem little confusing @ first, when start understand angular principles, shouldn't problem.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -