Html Code for datepicer
- <div class="form-group" style="margin-left:250px">
- <label class="col-sm-2 control-label">Birth Date:</label>
- <div class="col-sm-3">
- <p class="input-group">
- <input type="text" name="bday" id="bday" class="form-control" ng-focus="open($event)" ng-blur="out()" datepicker-popup="{{format}}" ng-model="newuser.bdate" is-open="opened" readonly="readonly" />
- <span class="input-group-btn">
- <button type="button" class="btn btn-default" ng-click="open($event)">
- <i class="glyphicon glyphicon-calendar"></i>
- </button>
- </span>
- </p>
- </div>
- </div>
You are select a 18/05/2015
Than alert message display a error
If you entered up to 18 year then out put look like this
JavaScript Code for Date control
-
- $scope.out = function()
- {
- var x = new Date($("#bday").val());
- var Cnow = new Date();
- if ($("#bday").val() == "")
- {
- $("#bday").focus();
- }
- else if (Cnow.getFullYear() - x.getFullYear() < 18)
- {
- alert('You Are Not 18 Year');
- $("#bday").val('');
- }
- else {}
- };
This code work focus out time if valid the no error found otherwise display error you are not 18 year old.
Thank You