嗨,我想通過asp的文本框控件驗證我。驗證日期時間現在時間現在時間
我希望它是空的,是今天還是將來不是過去的日期,並且日期格式是正確的MM/DD/YYY。
我已經寫了這個代碼爲:
If String.IsNullOrEmpty(txtPickupDate.Text) Then
lblError.Text = lblError.Text & "<BR>You must enter in the field Pickup Date."
lblError.Visible = True
rtn = False
Else
If txtPickupDate.Text > DateTime.Now.ToString("MM/DD/YYYY") Then
lblError.Text = lblError.Text & "<BR>You must enter in a valid date for Pickup."
lblError.Visible = True
rtn = False
Else
Dim Pickup As Date
If Date.TryParseExact(txtPickupDate.Text.ToString(), "mm/dd/yyyy", _
System.Globalization.CultureInfo.CurrentCulture, _
Globalization.DateTimeStyles.None, Pickup) Then
Else
lblError.Text = lblError.Text & "<BR>You must enter the Pickup Date in the format of MM/DD/YYYY."
lblError.Visible = True
rtn = False
End If
End If
End If
但是它不會對
工作如果txtPickupDate.Text> DateTime.Now.ToString( 「MM/DD/YYYY」 )然後
不做文字比較上最新數據。 https://dotnetfiddle.net/czRPsJ – Plutonix
你爲什麼不分析日期字符串? –
@Plutonix除非它是ISO 8601(http://en.wikipedia.org/wiki/ISO_8601)格式,並且日期介於[1000和10000之間)。 –