angularjs - Regular Expression date time using MVC Data Annotations -


i'm mixing mvc data annotations , angularjs validations ng-pattern. i've done far thing:

[regularexpression("/^[0-9]{4}-[0-9]{2}-[0-9]{2} 20|21|22|23|([0-1][0-9]):[0-5][0-9]:[0-5][0-9]$/", errormessage = "date format: yyyy-mm-dd hh:mm:ss")] 

as can see, try format date: yyyy-mm-dd hh:mm:ss. want make 24 hours time. problem form getting valid when type:

  • 2015-21 , 2015-22 // 2015-20 not valid, cannot understand why
  • 2015-12-20 21 // want user enter minutes , seconds, because has datetimepicker, more useful , sets format want

so, why regular expression not working expect?

your regex not work expected because did not use ^ anchor (although guess expression anchored, still better play safe) , did not enclose alternatives group, , 21, 22, 23 valid values.

here fixed expression:

^[0-9]{4}-[0-9]{2}-[0-9]{2} (?:20|21|22|23|(?:[0-1][0-9])):[0-5][0-9]:[0-5][0-9]$                             ^^^                         ^^  

see demo


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -