这个表达式([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})可以判断出2005-11-12但是2005-1-12也能通过,我想月或日写成1为的也提示错误。。

解决方案 »

  1.   

    if you insist on 2005-01-12, then try([0-9]{4})-([0-9]{2})-([0-9]{2})then again, this doesn't validate the date
      

  2.   

    string regx=@"\d{4}-(\d{2}|\d{1})-(\d{2}|\d{1})";
      

  3.   

    不分闰年的
    ([1-9]\d{3})-((0[13578])|(1[02])-(0[1-9])|([12]\d)|(3[01]))|((0[469])|(11)-(0[1-9])|([12]\d)|(30))|(02-(0[1-9])|([12]\d))
      

  4.   

    http://www.regexlib.com/DisplayPatterns.aspx?cattabindex=5&categoryId=5
    到这里看看