0

I would like validate the date inserted on the Pop UP Form on the front end by Angular JS. Because the wrong date would be stopped at the source. The date is in the format yyyy-MM-dd'T'HH:mm. I have the followed code:

<ng-form name="f.id">
  <input ng-if="f.type === 'datetime'" type="datetime-local" ng-model="f.value" ng-required="f.required" ng-change="updateScript()" />
  <input ng-if="f.type === 'host'" type="text" ng-model="f.value" ng-required="f.required" ng-change="updateScript()" />
  <input ng-if="f.type === 'port' || f.type === 'number'" type="text" ng-pattern="/^\d+$/" ng-model="f.value" ng-required="f.required" ng-change="updateScript()" />
  <input ng-if="f.type === 'path'" type="text" ng-model="f.value" ng-required="f.required" ng-pattern="/^((file)|(sftp)|(smb)):///" ng-change="updateScript()" />
  <textarea ng-if="f.type === 'text'"  ng-model="f.value" ng-required="f.required" ng-change="updateScript()"></textarea>                                      
  <select  ng-if="f.type === 'select'"  ng-options="item as item for item in f.availableValues" ng-model="f.value"
          type="{{f.type}}" ng-required="f.required" ng-change="updateScript()"></select>
  <div  ng-show="f.id.$dirty && f.id.$invalid">
    <span class="label label-warning">Required field </span>
  </div>
</ng-form>

How can I validate the date in the Pop up and show to the user an error message? Thanks.

morels
  • 2,095
  • 17
  • 24
Stefano
  • 1,439
  • 4
  • 23
  • 38
  • I would suggest using moment.js it allows to use something like moment(date, 'yyyy-MM-dd'T'HH:mm").isValid(); -> http://momentjs.com/docs/#/parsing/is-valid/ – Fer To Oct 21 '15 at 09:55
  • Possible duplicate of [AngularJS: How to validate date in US format?](http://stackoverflow.com/questions/14146655/angularjs-how-to-validate-date-in-us-format) – morels Oct 21 '15 at 10:04

0 Answers0