AngularJS: How to validate date in US format?

前端 未结 3 561
囚心锁ツ
囚心锁ツ 2020-12-14 22:55

I have the following form code that allows input of a date using AngularUI (date is required and should match US date format e.g.: MM/DD/YY):

3条回答
  •  忘掉有多难
    2020-12-14 23:10

    Your ng-pattern worked in a fiddle I created, but it allows for some incorrect dates, such as 0/9/1993 and 19/2/1993.

    Here's a better pattern: (note, it was updated to match @WillSadler's answer)

    ^(0?[1-9]|1[012])\/(0?[1-9]|[12][0-9]|3[01])\/((19\d{2})|([2-9]\d{3}))$
    

    Fiddle.

提交回复
热议问题