I am completely New to Angularjs and trying to validate 2 scenarios. I have 2 text boxes one with start date and the other with end date. I am checking
- Show validation error on UI if start date is not greater than or equal to today. It should be today or any day after today.
- Show validation error on UI if start date is greater than end date. End date should be greater than start date.
I tried the below code which did not work. Any suggestions please.
Html Code
<label for="endDate" class="control-label">Start Date:</label>
<div>
<input type="text" class="form-control"
id="startDate" ng-model="startDate" />
</div>
<label for="text" class="control-label">End Date:</label>
<div>
<input type="text" class="form-control"
id="endDate" ng-model="endDate"
ng-change='checkErr(startDate,endDate)' />
</div>
<span>{{errMessage}}</span>
js code
$scope.checkErr = function(startDate,endDate){
$scope.errMessage = '';
$scope.curDate = new Date();
if(startDate < endDate){
$scope.errMessage = 'End Date should be greate than start date';
return false;
}
if(startDate < curDate){
$scope.errMessage = 'Start date should not be before today.';
return false;
}
};
- I have input type as text for both date controls.I am using bootstrap date picker.