我使用此正则表达式验证日期为1/12/2018,uu / 12/2018,uu / uu / 2018,uu / uu / uu(uu未知)
(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)\d{2})$|(uu\/([1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])\/[0-9]{4})|(uu\/uu\/[0-9]{4})|(uu\/uu\/uuuu)
有没有办法修改它以接受字符串月而不是数字? 2018年12月1日,2018年1月1日等。
答案 0 :(得分:0)
找到它,以防万一有人在寻找它:
^(((31(?!\-Feb?|Apr?|June?|Sept?|Nov?))|((30|29)(?!\-Feb?))|(29(?=\-Feb?\-(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\d|2[0-8])\-(Jan?|Feb?|Mar?|May?|Apr?|Jul?|Jun?|Aug?|Oct?|Sep?|Nov?|Dec?)\-((1[6-9]|[2-9]\d)\d{2}))$|(uu\-(Jan?|Feb?|Mar?|May?|Apr?|Jul?|Jun?|Aug?|Oct?|Sep?|Nov?|Dec?)\-[0-9]{4})|(uu\-uuu\-[0-9]{4})|(uu\-uuu\-uuuu)