470,587 Members | 2,177 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,587 developers. It's quick & easy.

help - need to validate date and time in c#+asp.net

Hello,
What is the best way to validate a textbox to see if it contains a valid
date or a valid time or both?

Thanks

Frank
Nov 15 '05 #1
4 1818
You could either cast the value as a date and catch the exception if it
isn't one, or you could read up on Regular Expressions and use one to
validate the format.

RegExs are more elegant, but catching the exception is quick, dirty, and
effective.
"Frank Rocco" <fa*****@hotmail.com> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
Hello,
What is the best way to validate a textbox to see if it contains a valid
date or a valid time or both?

Thanks

Frank

Nov 15 '05 #2
Thanks Jeff, I'll look at the RegExp option.
Anyone have one already coded?
This seems like it would be a common thing to have.

Regards,

Frank

"Jeff Molby" <JeffMolby@C_mc_st.n_t> wrote in message
news:up*************@TK2MSFTNGP10.phx.gbl...
You could either cast the value as a date and catch the exception if it
isn't one, or you could read up on Regular Expressions and use one to
validate the format.

RegExs are more elegant, but catching the exception is quick, dirty, and
effective.
"Frank Rocco" <fa*****@hotmail.com> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
Hello,
What is the best way to validate a textbox to see if it contains a valid
date or a valid time or both?

Thanks

Frank


Nov 15 '05 #3
I don't have any code, but I'm sure it's out there somewhere. I refer you to
the almighty Google
http://www.google.com/search?hl=en&l...date+date+time
Correction: Instead of casting it as a date, you'll probably want to try
DateTime.Parse() instead.
http://www.dotnet247.com/247referenc...30/150304.aspx
"Frank Rocco" <fa*****@hotmail.com> wrote in message
news:up*************@TK2MSFTNGP12.phx.gbl...
Thanks Jeff, I'll look at the RegExp option.
Anyone have one already coded?
This seems like it would be a common thing to have.

Regards,

Frank

"Jeff Molby" <JeffMolby@C_mc_st.n_t> wrote in message
news:up*************@TK2MSFTNGP10.phx.gbl...
You could either cast the value as a date and catch the exception if it
isn't one, or you could read up on Regular Expressions and use one to
validate the format.

RegExs are more elegant, but catching the exception is quick, dirty, and
effective.
"Frank Rocco" <fa*****@hotmail.com> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
Hello,
What is the best way to validate a textbox to see if it contains a valid date or a valid time or both?

Thanks

Frank



Nov 15 '05 #4
Thanks for the help Jeff. That's what I needed.

Regards,

Frank

"Jeff Molby" <JeffMolby@C_mc_st.n_t> wrote in message
news:Om**************@tk2msftngp13.phx.gbl...
I don't have any code, but I'm sure it's out there somewhere. I refer you to the almighty Google
http://www.google.com/search?hl=en&l...date+date+time

Correction: Instead of casting it as a date, you'll probably want to try
DateTime.Parse() instead.
http://www.dotnet247.com/247referenc...30/150304.aspx
"Frank Rocco" <fa*****@hotmail.com> wrote in message
news:up*************@TK2MSFTNGP12.phx.gbl...
Thanks Jeff, I'll look at the RegExp option.
Anyone have one already coded?
This seems like it would be a common thing to have.

Regards,

Frank

"Jeff Molby" <JeffMolby@C_mc_st.n_t> wrote in message
news:up*************@TK2MSFTNGP10.phx.gbl...
You could either cast the value as a date and catch the exception if it isn't one, or you could read up on Regular Expressions and use one to
validate the format.

RegExs are more elegant, but catching the exception is quick, dirty, and effective.
"Frank Rocco" <fa*****@hotmail.com> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
> Hello,
>
>
> What is the best way to validate a textbox to see if it contains a valid > date or a valid time or both?
>
> Thanks
>
> Frank
>
>



Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Megha Vishwanath | last post: by
6 posts views Thread by mike | last post: by
6 posts views Thread by paulsmith5 | last post: by
7 posts views Thread by Jack Addington | last post: by
18 posts views Thread by Q. John Chen | last post: by
6 posts views Thread by D | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.