【发布时间】:2019-11-06 16:08:07
【问题描述】:
我正在尝试创建一个程序来验证格式为 DDMMYYYY 的输入日期的格式。我尝试使用while 循环的集合来执行此操作,但它似乎不起作用,我不知道为什么!
这是我的代码:
Console.WriteLine("Enter your date of birth (DDMMYYYY): ")
Dim dob As String = Console.ReadLine
While CInt(Mid(dob, 3, 2)) > 12 Or CInt(Mid(dob, 3, 2)) < 1
Console.WriteLine("x-----x")
Console.WriteLine("Format Incorrect!")
Console.WriteLine("Enter your date of birth: ")
dob = Console.ReadLine
End While
While CInt(Mid(dob, 3, 2)) = 4 Or 6 Or 9 Or 1 And CInt(Mid(dob, 1, 2)) > 30
Console.WriteLine("x-----x")
Console.WriteLine("Format Incorrect!")
Console.WriteLine("Enter your date of birth: ")
dob = Console.ReadLine
End While
While CInt(Mid(dob, 3, 2)) = 2 And CInt(Mid(dob, 1, 2)) > 29
Console.WriteLine("x-----x")
Console.WriteLine("Format Incorrect!")
Console.WriteLine("Enter your date of birth: ")
dob = Console.ReadLine
End While
While CInt(Mid(dob, 1, 2)) < 1
Console.WriteLine("x-----x")
Console.WriteLine("Format Incorrect!")
Console.WriteLine("Enter your date of birth: ")
End While
Console.WriteLine("Thank You!")
我研究了其他方法,但没有找到任何适合我正在寻找的解决方案。
【问题讨论】:
标签: vb.net date validation format