Thứ Tư, 9 tháng 10, 2019

regex javascript dd/MM/yyyy

+ 31 day months
(0[13578]|1[02])[\/.](0[1-9]|[12][0-9]|3[01])[\/.](18|19|20)[0-9]{2}
(0[1-9]|[12][0-9]|3[01])[\/.](0[13578]|1[02])[\/.](18|19|20)[0-9]{2}

+ 30 day months
(0[469]|11)[\/.](0[1-9]|[12][0-9]|30)[\/.](18|19|20)[0-9]{2}
(0[1-9]|[12][0-9]|30)[\/.](0[469]|11)[\/.](18|19|20)[0-9]{2}

+ February 1-28 always valid
(02)[\/.](0[1-9]|1[0-9]|2[0-8])[\/.](18|19|20)[0-9]{2}
(0[1-9]|1[0-9]|2[0-8])[\/.](02)[\/.](18|19|20)[0-9]{2}

+ February 29 also valid on leap years
(02)[\/.]29[\/.](((18|19|20)(04|08|[2468][048]|[13579][26]))|2000)
29[\/.](02)[\/.](((18|19|20)(04|08|[2468][048]|[13579][26]))|2000)

==> which means it would be this if you put it all together:

Năm nhuận:
a) dd/MM/yyyy
((0[1-9]|[12][0-9]|3[01])[\/.](0[13578]|1[02])[\/.](18|19|20)[0-9]{2})|((0[1-9]|[12][0-9]|30)[\/.](0[469]|11)[\/.](18|19|20)[0-9]{2})|((0[1-9]|1[0-9]|2[0-8])[\/.](02)[\/.](18|19|20)[0-9]{2})|(29[\/.](02)[\/.](((18|19|20)(04|08|[2468][048]|[13579][26]))|2000))

b) dd/MM/yyyy cho phép số 0 có hoặc không ở ngày/tháng


((0?[1-9]|[12][0-9]|3[01])[\/.](0?[13578]|1[02])[\/.](18|19|20)[0-9]{2})|((0?[1-9]|[12][0-9]|30)[\/.](0?[469]|11)[\/.](18|19|20)[0-9]{2})|((0?[1-9]|1[0-9]|2[0-8])[\/.](0?2)[\/.](18|19|20)[0-9]{2})|(29[\/.](0?2)[\/.](((18|19|20)(04|08|[2468][048]|[13579][26]))|2000))

Chuẩn hơn cho dấu - và / :
((0?[1-9]|[12][0-9]|3[01])[\/](0?[13578]|1[02])[\/](18|19|20)[0-9]{2})|((0?[1-9]|[12][0-9]|30)[\/](0?[469]|11)[\/](18|19|20)[0-9]{2})|((0?[1-9]|1[0-9]|2[0-8])[\/](0?2)[\/](18|19|20)[0-9]{2})|(29[\/](0?2)[\/](((18|19|20)(04|08|[2468][048]|[13579][26]))|2000))|((0?[1-9]|[12][0-9]|3[01])[\-](0?[13578]|1[02])[\-](18|19|20)[0-9]{2})|((0?[1-9]|[12][0-9]|30)[\-](0?[469]|11)[\-](18|19|20)[0-9]{2})|((0?[1-9]|1[0-9]|2[0-8])[\-](0?2)[\-](18|19|20)[0-9]{2})|(29[\-](0?2)[\-](((18|19|20)(04|08|[2468][048]|[13579][26]))|2000))

c) MM/dd/yyyy
((0[13578]|1[02])[\/.](0[1-9]|[12][0-9]|3[01])[\/.](18|19|20)[0-9]{2})|((0[469]|11)[\/.](0[1-9]|[12][0-9]|30)[\/.](18|19|20)[0-9]{2})|((02)[\/.](0[1-9]|1[0-9]|2[0-8])[\/.](18|19|20)[0-9]{2})|((02)[\/.]29[\/.](((18|19|20)(04|08|[2468][048]|[13579][26]))|2000))

Không có nhận xét nào:

Đăng nhận xét