如何验证日期 [英] how to validate a date

查看:70
本文介绍了如何验证日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在验证日期时遇到问题,我有一个带有jquery日历放置的文本框(tbDate),但仍然被告知必须验证该日期,我知道了以下方法,但它似乎对我不起作用,如果还有其他方法,请提出建议和帮助,非常感谢.

Hi all, I''m having problems validating my date, I got a text box (tbDate) with a jquery calendar drop, but I''m still been told that I must validate that date, I''ve got the following method but it doesn''t seem to be working for me, if there is any other way please advise and help, thanks alot.

DateTime validate;
        if (DateTime.TryParse(tbDOB.Text, out validate))
        {
            update.Parameters.AddWithValue("@dob", tbDOB.Text);

        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Window", "alert('Enter Valid Date');", true);

        }

推荐答案

U可以验证您的日期使用带有rejex表达式的Javascript

http://www.roseindia.net/answers/viewqa/JavaScriptQuestions/25909-javascript-date-validation-using-regex.html [
U Can validate your date Using Javascript with rejex expression

http://www.roseindia.net/answers/viewqa/JavaScriptQuestions/25909-javascript-date-validation-using-regex.html[^]

or if u want to validate in server side just use try.. catch.

Try

{
   Datetime myDate = Datetime.Parse(someTextBox.Text)
}

Catch (Exception ex)
{

   'Not a valid Date

'your Msg Goes Hear....
   'Do Something



}



}


这篇关于如何验证日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆