繁体   English   中英

如何进行格式检查? 所以输入的格式正确。 例如日/月/年。 (Visual Basic)

[英]How do i do a format check? so the input is in the correct format. E.g. dd/mm/yy. (Visual Basic)

如何进行格式检查?所以输入的格式正确。例如。日/月/年。 (Visual Basic) 如何进行格式检查? 所以输入的格式正确。 例如日/月/年。 (Visual Basic)

我早就说过,查看值是否采用正确格式的最佳方法是实际尝试解析它 这具有作为完美验证检查的优点,而不仅仅是一种启发式方法,并且为您提供要使用的目标类型的实例,这通常是下一步。

因此我建议DateTime.TryParseExact() 这是一个基本示例:

Dim input As String = " ... "
Dim result As DateTime
Dim format = "dd/MM/yyyy"
If DateTime.TryParseExact(input, format, Nothing, Nothing, result) Then
    ' The input is in the correct format
Else
    ' The input is NOT in the correct format
End If

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM