Check several date formats using DateTime.TryParse()

后端 未结 5 1985
北荒
北荒 2021-01-05 02:34

I\'m using a method to validate textboxes.

    public bool ValidateDateTimeTextBoxes(params TextBox[] textBoxes)
    {
        DateTime value = DateTime.Toda         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-05 02:52

     public bool ValidateDateTimeTextBoxes(params TextBox[] textBoxes)
        {
            DateTime value = DateTime.Now;
            //string dateFormat = "dd/mm/yyyy";
    
            foreach (var textBox in textBoxes)
            {
                if (!DateTime.TryParse(textBox.Text,"dd/mm/yyyy",new CultureInfo("en-US"), 
                              DateTimeStyles.None out value))
                {
                    return false;
                }
            }
    
            return true;
        }
    

提交回复
热议问题